Ends in 7 days

BLACK FRIDAY: Receive 83% off Programiz PRO

+🎁 Buy 1 year, gift 1 year FREE — Split with a friend for just $49.50 each

Start FREE trial →
Background Image

Buy 1 year, Gift 1 year —completely FREE

Start FREE trial →
Sanjana S K
2 months ago
Sanjanacountry asked

How to print double values in Java?

Sarthak Baral
Expert
2 months ago
Sarthak Baral answered

Good question! To print double values in Java, you can use the same `System.out.println()` method that you've already seen.

Just like with integers, you can write a double value directly without using quotation marks, but you should remember to include a decimal point. Here’s an example:

class Main {
    public static void main(String[] args) {
        System.out.println(3.14);
    }
}

Output

3.14

In this case, `3.14` is a double value, and it prints out just like the integer examples. If you want to print multiple values, you can do that in a single `println` statement as well:

System.out.println(3.14 + " and " + 2.71);

Output

3.14 and 2.71

Hope this helps! Let me know if you have more questions.

Java
This question was asked as part of the Learn Java Basics course.