Exercise 2.11 Solution:
package exercise;
import java.util.Scanner;
//********************************************************************************
// Author: Biren Patel
// exercise.java To solve the exercise 2.11
//********************************************************************************
public class exercise {
public static void main(String[] args)
{
int iResult, num1 = 25, num2 = 40, num3 = 17, num4 = 5;
double fResult, val1 = 17.0, val2 = 12.78;
System.out.println("answer f: " + (fResult = val1 / val2));
System.out.println("answer g: " + (iResult = num1 / num2));
System.out.println("answer h: " + (fResult = (double) num1 / num2));
System.out.println("answer i: " + (fResult = num1 / (double) num2));
System.out.println("answer j: " + (fResult = (double) (num1 / num2)));
System.out.println("answer k: " + (iResult = (int) (val1 / num4)));
System.out.println("answer l: " + (fResult = (int) (val1 / num4)));
System.out.println("answer m: " + (fResult = (int) ((double) num1 / num2)));
System.out.println("answer n: " + (iResult = num3 % num4));
System.out.println("answer o: " + (iResult = num2 % num3));
System.out.println("answer p: " + (iResult = num3 % num2));
System.out.println("answer q: " + (iResult = num2 % num4));
}
}
No comments:
Post a Comment