Menu
Question Index
...

What will be the output of the following program? (Approximately)

public class HarmonicSeries
{
    public static void main(String args[])
    {
        int num = 5;
        double result = 0.0;
        while (num > 0)
        {
            result = result + (double) 1 / num;
            num--;
        }
        System.out.println(result);
    }
}


2.28
1.8
0
1.0
Compilation Error or Runtime Error

Doubts

Problems

Topic: while Loop 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