Sanjana S K
last week
Sanjanacountry asked

How to print double values in Java?

Sarthak Baral
Expert
last week
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.