Menu
Question Index
...

What will be the output of the following program?

public class TruthAlwaysTriumphs {

    public static void main(String[] args) {
        print(0);
        print(1);
        print(2);
        print(-1);
        print(3);
    }

    public static void print(int i) {
        boolean result = true;
        switch (i) {
            case 0 :
                result &= (5 > 7);
            case 1 :
                result = result || 7 > i++;
            case 2 :
                result = result ^ result;
                break;
            default :
                result = false;
        }
        System.out.print(result ? "(F)" : "(T)" + i);
    }
}


(T)1(T)1(T)2(T)-1(T)3
(T)0(T)1(T)2(T)-1(T)3
(F)0(F)1(F)2(F)-1(F)3
Some other output or Compilation Error

Doubts

Problems

Topic: Java Methods - Parameter Passing And Scope

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App