141k views
0 votes
What is the output of the code below?

double num = 56.4321;
System.out.printf("%.2f", 56.4321);

%.2f
%.2f56.4321
56.43
56.4321

1 Answer

6 votes

Answer:

The output of the given code is 56.43

Step-by-step explanation:

As the code is given in java language the following are the code

public class code

{

public static void main(String[] args)

{

double num = 56.4321;

System.out.print("%.2f", 56.4321);

}

}

The %f means that it print the floating point number and .2 means that it print the first two digit of the given number after the point .

so " %.2f "means that it print the value first 2 digit of floating point number after the point .

Therefore it print 56.43

User E LaRoche
by
8.9k points