Java MCQ Questions on Control Flow Statements

This section focuses on the "Control Flow Statements" in Java programming. These Multiple Choice Questions (MCQ) should be practiced to improve the Java programming skills required for various interviews (campus interviews, walk-in interviews, company interviews), placements and other competitive examinations.

1. What will be the output of the following code snippet?

  
int a=15;
int b=25;
if ((a < b ) || ( a = 5)>15)
	system.out.println(a);
else
	system.out.println(b);

A. Error
B. 15
C. 25
D. No output

View Answer


2. What will be the output of the program?

int x, y;
x=15; y=20;
if (x>15)
if(y>15)
{
	system.ptintln("y is "+y);
}
else
	system.out.ptintln("x is "+x);

A. Error
B. y is 20
C. x is 15
D. No output

View Answer


3. Which two are acceptable types for x?

switch(x)
{
	default:
		System.out.println("Hello");
}

A. short
B. char
C. long
D. float

View Answer


4. Which statement is true?

public void test(int x)
{
	int odd = 1;
	if(odd) /* Line 4 */
	{
		System.out.println("odd");
	}
	else
	{
		System.out.println("even");
	}
}

A. Compilation fails.
B. "odd" will always be output.
C. "even" will always be output.
D. "odd" will be output for odd values of x, and "even" for even values.

View Answer


5. Which statement is true?

public class While
{
	public void loop()
	{
		int x= 0;
		while ( 1 ) /* Line 6 */
		{
			System.out.print("x plus one is " + (x + 1)); /* Line 8 */
		}
	}
}

A. There is a syntax error on line 1.
B. There are syntax errors on lines 1 and 6.
C. There are syntax errors on lines 1, 6, and 8.
D. There is a syntax error on line 6.

View Answer


6. Which of the following for loop declaration is not valid?

A. for ( int i = 99; i >= 0; i / 9 )
B. for ( int i = 7; i <= 77; i += 7 )
C. for ( int i = 20; i >= 2; - -i )
D. for ( int i = 2; i <= 20; i = 2* i )

View Answer


7. _______ is not a flow control statement in Java.

A. break
B. continue
C. exit()
D. return

View Answer


8. The break statement causes an exit from ______ loop.

A. innermost
B. outermost
C. break statement causes an exit from program
D. Depends on program

View Answer


9. Which of the following is an iteration statement?

A. switch
B. if-else
C. if
D. do-while

View Answer


10. What is the valid data type for variable "a" to print "Hello World"?

switch(a)
{
   System.out.println("Hello World");
}

A. int and float
B. byte and short
C. char and long
D. byte and char

View Answer






Also check :

Discussion


* You must be logged in to add comment.