Q: What is the output of the Java program? String name1="FOX", name2="DOG"; if(name1 == "FOX") System.out.print("FOX "); System.out.println("GOOD"); if(name2 == "CAT") System.out.println("DINO");
Solution: The second Print statement "GOOD" is always executed.
Q: What is the output of the Java program? String name="dino"; if(name == "dino") System.out.print("DINO"); System.out.println("GOOD");
Solution: The second Print statement is not part of the IF statement. So it is always executed.
Q: What is the output of the Java program with IF-ELSE-IF statements? int marks=55; if(marks >= 80) System.out.println("DISTINCTION"); else if(marks >=35) System.out.println("PASS"); else System.out.println("FAIL");
Solution: no solution
Q: What is is the output of the Java program? int marks=85; if(marks >= 80) System.out.println("DISTINCTION"); else if(marks >=35) System.out.println("PASS");
Solution: It is ok to skip the ELSE statement.
Q: What is the output of Java program below? float temp = 98.4f; if(temp > 98.4) { System.out.println("SUMMER"); } else { System.out.println("UNKNOWN"); }
Solution: no solution
Q: What is the output of the Java program? long num = 123L; if(num > 123) { System.out.println("TIGER"); } else { System.out.println("BIRD"); }
Solution: no solution
Q: What is the output of the Java program? int horses = 10; int camels = 5; if(horses > 5) { if(camels > 3) { System.out.println("FOREST"); } } else { System.out.println("CITY"); }
Solution: Nesting of IF and ELSE is allowed in Java.
Q: What is the output of the Java program? int horses = 10; int camels = 5; if(horses < 5) { System.out.println("TOWN"); } else if(horses >=5) System.out.print("FOREST "); System.out.println("AMAZON"); else System.out.println("UNKNOWN");
Solution: ELSE-IF statement should not contain more than one statement without braces { }.
Q: What is the output of the Java program? int marks=29; if(marks > 29); System.out.print("PASS "); System.out.println("RANK");
Solution: Notice the immediate Semicolon (;) after the IF. It ends the IF block. So whatever is next or below it will be executed always.
Q: What is the output of the Java program below? if(3>1) { 4; }
Solution: 4; is not a valid statement.
You Have Score    | /10 |