Arithmetic looks as expected, with one rule that bites everyone once: dividing two int values gives an int, rounded toward zero. 7 / 2 is 3; 7 / 2.0 is 3.5, because one side is a double. % is the remainder: 7 % 3 is 1, and n % 2 == 0 tests for even. (int) 3.9 truncates to 3; (double) 7 makes 7.0.
The Math class has the rest: Math.max(a, b), Math.abs(x), Math.pow(2, 10) (a double), Math.sqrt(16), Math.round(2.5) (a long). += and ++ are shorthand: total += x adds to total, count++ adds one.
int a = 17, b = 5;
System.out.println(a / b); // 3
System.out.println(a % b); // 2
System.out.println(a / (double) b); // 3.4
System.out.println(Math.max(a, b)); // 17Your task
Fill in the four static variables from the starter: quotient is minutes / 60 as whole hours, remainder is the minutes left over, exact is the division as a double (so 150 minutes is 2.5), and rounded is exact rounded to the nearest whole number with Math.round, stored as a long.
Hint 1
quotient = minutes / 60 and remainder = minutes % 60: both sides are int, so the division is whole.
Hint 2
exact = minutes / 60.0; the 60.0 makes it a double division. rounded = Math.round(exact).
Show the solution
public class Main {
static int minutes = 150;
static int quotient = minutes / 60;
static int remainder = minutes % 60;
static double exact = minutes / 60.0;
static long rounded = Math.round(exact);
public static void main(String[] args) {
System.out.println(quotient + " hours and " + remainder + " minutes");
}
}