Menu
Question Index
...

What will be the output of the following program?

public class Result {
    public static void main(String args[]) {
        int num = Integer.parseInt("10");
        double result = 0.0;
        while (num > 0) {
            result = result + 1 / num;
            num--;
        }
        String output = "" + result;
        System.out.println("Output = " + output.substring(0, 5));
    }
}


Output = 2.928
Output = 2.9289
Output = 2.92896
Some other output
Compilation Error or Runtime Error

Doubts

Problems

Topic: Converting Numbers to and from Strings In Java

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App