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") );
	}
}
  1. yes
  2. no
  3. Error

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 ");

  1. first second third
  2. first second fourth
  3. first fourth
  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);
	}
}
  1. 55
  2. 45
  3. 20
  4. 10

Page 1



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.