Challenge: Chop the Decimals

Lab Java Beginner 10 points

Start with double price = 499.99;. Print the price, then the price cast to an int, then the text "42" turned into a number plus 8:

499.99
499
50

Input

None.

Output

The three lines above.

Example

Output

499.99
499
50
Sample output available
Editor
Java

Hints

(int) price chops off the decimals.

Integer.parseInt("42") turns the text into the number 42.

Solution explanation

A cast to int drops everything after the decimal point, and Integer.parseInt converts text to a whole number.

Show solution
public class Main {
    public static void main(String[] args) {
        double price = 499.99;
        System.out.println(price);
        System.out.println((int) price);
        System.out.println(Integer.parseInt("42") + 8);
    }
}
Output
Answer
HOME LABS COMMUNITY DASHBOARD