Menu
Question Index
...

What will be the output of the following program?

public class MathsIsFun {
    public static void main(String[] args) {
        float x = (float) Math.cos(45);
        float y = (float) Math.sin(45);
        double result = (x * x) + (y * y);
        System.out.format("%.3f, ", x);
        System.out.format("%.3f, ", y);
        System.out.format("%.3f, ", x * x);
        System.out.format("%.3f, ", y * y);
        System.out.print(result);
    }
}


0.525, 0.851, 0.276, 0.724, 1.0
0.707, 0.707, 0.500, 0.500, 0.99994
0.707, 0.707, 0.500, 0.500, 1.0
0.154, -0.988, 0.024, 0.976, 1.0
Compilation Error or Runtime Error

Doubts

Problems

Topic: Java Formatting Numbers

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App