Formatted Output

Lab Java Beginner 10 points

Use System.out.printf to print Pi is about 3.14 using the value Math.PI with 2 decimal places, followed by a new line.

Input

None.

Output

Pi is about 3.14

Example

Output

Pi is about 3.14
Sample output available
Editor
Java

Hints

%.2f formats a decimal number with 2 digits after the point.

%n is a platform-independent new line.

Solution explanation

printf fills placeholders such as %d (integer), %s (string) and %.2f (decimal) with the values that follow.

Show solution
public class Main {
    public static void main(String[] args) {
        System.out.printf("Pi is about %.2f%n", Math.PI);
    }
}
Output
Answer
HOME LEARN COMMUNITY DASHBOARD