← all problems

Round a negative number 🌶️🌶️

change holds a negative decimal number, like -3.6. The locked line at the bottom prints a variable named roundedChange (an int you have to create) which should hold change rounded to the nearest whole number: -3.6 rounds to -4 and -3.4 rounds to -3. Rounding a negative number with a cast works a little differently from rounding a positive one: a cast always moves toward zero, so to round a negative number you have to push it away from zero first. Your code will be tested with several different values.

Main.java — the program frame below is already written; you're only completing the code in the editable box. Your code will be run several times, each with different starting values for the variables at the top.

public class Main {
    public static void main(String[] args) {
        double change = -3.6;
        // ---- write your code below ----
        System.out.println(roundedChange);
    }
}