Thursday, July 15, 2021

Java Quiz-4(if-else)

Java Multiple Choice Questions(if-else)


1. An IF or ELSE IF statement accepts ___ as input before branching.

A.boolean
B.int
C.float
D.char


2. An ELSE statement must be preceded by ___ statement in Java.

A.IF
B.ELSE IF
C.IF or ELSE IF
D.NONE


3. The condition of an IF statement evaluates to boolean only if the expression contains?

A.logical operators
B.relational operators
C.boolean operands
D.ALL


4. An IF-ELSE statement is better than a SWITCH statement in which scenario below?

A.Checking for More-than condition
B.Checking for Less-than condition
C.Checking for Ranges
D.ALL


5. What is the output of Java program with IF statement?

if(1)
{
  System.out.println("OK");
}
A.OK
B.No output
C.Compiler error
D.NONE


6. What is the output of the Java program?

int a=10;
if(a==9)
  System.out.println("OK ");
  System.out.println("MASTER");					
else
  System.out.println("BYE");
A.OK MASTER
B.BYE
C.Compiler error
D.NONE


7. 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");
A.FOX DINO
B. FOX GOOD DINO
C.Compiler error
D.NONE


8. What is the output of the Java program?

String name="dino";
if(name == "dino")
	System.out.print("DINO");
System.out.println("GOOD");
A. DINO GOOD
B.DINO
C.GOOD
D.Compiler error


9. 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");
A.DISTINCTION
B.PASS
C.Compiler error
D.NONE


10. Which of the following is not a decision-making statement?

A.if-else
B.if-else if
C.switch
D.for


11. Which of the following is not a branching statement.

A.if-else
B.break
C.continue
D.return


12. Which is not a looping statement?

A.for
B.while
C.if-else if-else
D.do-while


13.  Which of these selection statements test only for equality?

A.if
B.switch
C.if & switch
D.for


14. Which of the following loops will execute the body of loop even when condition controlling the loop is initially false?

A.for
B.if
C.switch
D.do-while


15. What will be the output of the following Java program?

 public static void main(String args[])
     {
         int a = 5; 
         int b= 6;
         if ((a= 1) == b)
             System.out.print(a);
         else 
             System.out.print(++a);
     }
A.5
B.4
C.7
D.2