Decision Making
- What is the output of this program?
public class jump_statment_Example
{
public static void main(String args[])
{
int p = 4;
int q = 5;
for ( ; q < 10; ++q)
{
if (q % p == 0)
{
continue;
}
else if (q == 10)
{
break;
}
else
{
System.out.print(q + " ");
}
}
}
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: A
Whenever q is divisible by x remainder body of loop is skipped by continue statement, therefore if condition q == 10 is never true as when y is 10, remainder body of loop is skipped by continue statements of first if. Control comes to print statement only in cases when q is odd.
output: 5 6 7 9
- What is the output of this program?
public class selection_statement_Example
{
public static void main(String args[])
{
int num1 = 10;
int num2 = 20;
if ((num2 = 5) == num1)
{
System.out.print(num2);
}
else
{
System.out.print(++num2);
}
}
}
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
num2 is initialised to 5. The conditional statement returns false and the else part gets executed.
output: 6
- Which of these statement is incorrect?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: D
No two case constants in the same switch can have identical values.
- Which of these jump statements can skip processing remainder of code in its body for a particular iteration?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: B
Ans: continue
- Which of these are selection statements in Java?
-
View Hint View Answer Discuss in Forum
NA
Correct Option: C
Continue and break are jump statements, and for is an looping statement.