← all problems

Whole dollars 🌶️

The program below is supposed to figure out how many whole dollars are in a price, then print that value. Try running it exactly as it is first, and read the compiler's error message; it's telling you something about assigning a double value to an int variable. Once you understand what it's complaining about, fix it using a cast: writing a type name in parentheses, like (int), directly in front of a value tells Java "convert this value to this type," even when that conversion might lose information. Your code will be tested with several different prices.

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 price = 19.99;
        // ---- write your code below ----
        System.out.println(wholeDollars);
    }
}