What will be the output of the following Java code?

class Output 
{
    public static void main(String args[]) 
    {
        long start, end;   
        start = System.currentTimeMillis();
        for (int i = 0; i < 10000000; i++);
        end = System.currentTimeMillis();
        System.out.print(end - start);
    }
}

a) 0
b) 1
c) 1000
d) System Dependent

1 thought on “What will be the output of the following Java code?”

  1. d
    Explanation: end time is the time taken by loop to execute it can be any non zero value depending on the System.
    Output:
    $ javac Output.java
    $ java Output
    78

Leave a Comment