Home »
Java Aptitude Que. & Ans.
Java conditional statements Aptitude Questions and Answers (page 2)
This section contains Aptitude Questions and Answers on Java Conditional Statements like if else, switch case statement, conditional statements etc.
List of Java Conditional Statements Aptitude Questions
6)
What will be the output of following program?
public class temp
{
public static void main(String args[])
{
int x=10;
System.out.println( ((x=5)?"yes":"no") );
}
}
- yes
- no
- Error
Correct Answer: 3
Error
Only boolean value is allowed in conditional expression.
7)
What will be printed by following code snippet?
double x = 6.2;
if(x-- >= 6.0)
System.out.print("first ");
if(--x >= 5.0)
System.out.print("second ");
if(x-- >= 4.0)
System.out.print("third ");
else
System.out.print("fourth ");
- first second third
- first second fourth
- first fourth
- first third
Correct Answer: 4
first third
8)
What will be the output of following program?
public class temp
{
public static void main(String agrs[])
{
int x=10;
switch(x)
{
case 5: x+= 5;
case 10: x+=10;
case 15: x+=15;
case 20: x+=20;
}
System.out.println(x);
}
}
- 55
- 45
- 20
- 10
Correct Answer: 1
55
Since there is no break in switch blocks, program's execution move to case 10: and fall down to case 20:
Page 1