A. if-else
B. do-while
C. switch
D. if
Ans: B
Q 2. Which of the following is used with the switch statement?
A. break
B. do
C. Exit
D. Continue
Ans: A
Q 3. Give the output
public void show()
{
int a=20;
if(a<=0)
{
if(a==0)
{
System.out.print("Mera");
}
else
{
System.out.print("Bharat");
}
}
System.out.print("Mahan");
}
A. Mera
B.Bharat
C. Mahan
D.BharatMahan
Ans: C. The first condition (if(a<=0)) is false so the control skips the if body and executes System.out.print("Mahan");
Q 4. Give the output
public void show()
{
int a=4,b=5;
for(; b<10;b++)
{
if(b%a==0)
{
continue;
}
else if(b==10)
{
break;
}
else
{
System.out.print(b+ " ");
}
}
}
Q 2. Which of the following is used with the switch statement?
A. break
B. do
C. Exit
D. Continue
Ans: A
Q 3. Give the output
public void show()
{
int a=20;
if(a<=0)
{
if(a==0)
{
System.out.print("Mera");
}
else
{
System.out.print("Bharat");
}
}
System.out.print("Mahan");
}
A. Mera
B.Bharat
C. Mahan
D.BharatMahan
Ans: C. The first condition (if(a<=0)) is false so the control skips the if body and executes System.out.print("Mahan");
Q 4. Give the output
public void show()
{
int a=4,b=5;
for(; b<10;b++)
{
if(b%a==0)
{
continue;
}
else if(b==10)
{
break;
}
else
{
System.out.print(b+ " ");
}
}
}
A. 5 6 7 9
B.1 2 3 4 5
C. 2 3 4 5
D.6 7 8 9
Ans: A. During first three iterations control goes to else body and the value of 'b' gets displayed. In the 4th iteration, control enters the if body (continue statement is encountered). Next value of 'b' is 9, so it is displayed and when 'b' becomes 10, condition of the loop is false.
B.1 2 3 4 5
C. 2 3 4 5
D.6 7 8 9
Ans: A. During first three iterations control goes to else body and the value of 'b' gets displayed. In the 4th iteration, control enters the if body (continue statement is encountered). Next value of 'b' is 9, so it is displayed and when 'b' becomes 10, condition of the loop is false.
Q 5:Give the output
public void show()
{
int num1 = 10;
int num2 = 20;
if ((num2 = 5) == num1)
{
System.out.print(num2);
}
else
{
System.out.print(++num2);
}
}
public void show()
{
int num1 = 10;
int num2 = 20;
if ((num2 = 5) == num1)
{
System.out.print(num2);
}
else
{
System.out.print(++num2);
}
}
A. 5
B. 4
C. 6
D. 7
Ans: C num2 is initialised to 5. The conditional statement returns false and the else part gets executed.
Q 6:Give the output
Which of these statement is incorrect?
A. switch statement is more efficient than a set of nested if
B. switch statement can only test for equality, whereas if statement can evaluate any type of boolean expression
C. it is possible to create a nested switch statements
D. two case constants in the same switch can have identical values
B. 4
C. 6
D. 7
Ans: C num2 is initialised to 5. The conditional statement returns false and the else part gets executed.
Q 6:Give the output
Which of these statement is incorrect?
A. switch statement is more efficient than a set of nested if
B. switch statement can only test for equality, whereas if statement can evaluate any type of boolean expression
C. it is possible to create a nested switch statements
D. two case constants in the same switch can have identical values
Ans: D
Q 7: Which of these selection statements test only for equality?
A. switch
B. if & switch
C. if
D. None of these
Ans: A
Q 8: In a switch case, when the switch value does not respond to any case then the execution transfers to:
A. a break statement
B. a default case
C. a loop
D. none
Ans: B
Q 7: Which of these selection statements test only for equality?
A. switch
B. if & switch
C. if
D. None of these
Ans: A
Q 8: In a switch case, when the switch value does not respond to any case then the execution transfers to:
A. a break statement
B. a default case
C. a loop
D. none
Ans: B
Q 9: Condition is essentially formed by using:
A. Arithmetic operators
B. Relational operators
C. Logical operators
D. All
Ans: D
Q 10: If(a>b)&&(a>c)), then which of the statement is true?
A. b is the smallest number
B. b is the greatest number
C. a is the greatest number
D. all of the above
Ans: C
A. Arithmetic operators
B. Relational operators
C. Logical operators
D. All
Ans: D
Q 10: If(a>b)&&(a>c)), then which of the statement is true?
A. b is the smallest number
B. b is the greatest number
C. a is the greatest number
D. all of the above
Ans: C
Q 12:
if(a>b)
c=a;
else
c=b;
It can be written as:
A. c= (b>a)?a:b;
B. c= (a!=b)?a:b;
C. c= (a>b)?b:a;
D. None
And: D
Q 13:Which of the following statements accomplishes 'fall through'?
A. for statement
B. switch statement
C. if-else
D. none
Ans: B
Q 14 A Java program executes but doesn't give the desired output.
It is due to:
A. the logical error in the program
B. the syntax error in the program
C. the run time error in the program
D. none
Ans: A
No comments:
Post a Comment