Decision Making
- Which of the following is not a valid jump statement?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
break, continue and return transfer control to another part of the program and returns back to caller after execution. However, goto is marked as not used in Java.
- Which of the following is not a decision making statement?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
do-while is an iteration statement. Others are decision making statements.
- What is the valid data type for variable “a” to print “Interview Mania”?
switch(p)
{
System.out.println("Interview Mania");
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
The switch condition would only meet if variable “a” is of type byte or char.
- Which of the following is used with the switch statement?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
Break is used with a switch statement to shift control out of switch.
- What would be the output of the following codesnippet if variable p=20?
public class Result
{
public static void main(String args[])
{
int p=20;
if(p<=0)
{
if(p==0)
{
System.out.println("5 ");
}
else
{
System.out.println("10 ");
}
}
System.out.println("15 ");
}
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
Since the first if condition is not met, control would not go inside if statement and hence only statement after the entire if block will be executed.