← all problems

Round to the nearest whole number 🌶️🌶️

The variable temperature holds a positive temperature with a decimal part, like 71.6. The locked line at the bottom prints a variable named roundedTemperature — an int that you have to create — which should hold temperature rounded to the nearest whole number: 71.6 rounds to 72, 71.4 rounds to 71, and 68.5 rounds up to 69. A cast by itself throws the decimal part away instead of rounding, so you'll need to combine it with one more step. Your code will be tested with several different temperatures.

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 temperature = 71.6;
        // ---- write your code below ----
        System.out.println(roundedTemperature);
    }
}