Java Control (Looping) Statements Aptitude Questions and Answers. Page 2

List of Control (Loop) Statements Aptitude Questions

6) What will be the output of following program?
public class temp
{
	public static void main(String agrs[])
	{
		for(int i=1, int j=1; i<5 ; i++, j++)
			System.out.print(i+""+j);
	}
}
  1. 1122334455
  2. 12345
  3. 11223344
  4. Error

7) What will be the output of following program?
public class temp
{
	public static void main(String agrs[])
	{
		
		for(int i=1, j=1; i<5 ; i++, j++)
			System.out.print(i+""+j);
	}
}
  1. 1122334455
  2. 12345
  3. 11223344
  4. Error

8) Consider the given code snippet and select the correct answer.
for(int i=1, j=1; i<5 ; i++, j++)
	System.out.print(i+j);
  1. 2468
  2. 12345
  3. 11223344
  4. Error

9) How many times "Hello world!" will be printed? (Consider the following code snippet).
int x = 2;
int y = 8;
while(x<(y+5))
{			
	System.out.println("Hello world!");
	x+=2;
	y-=2;
}
  1. 3
  2. 4
  3. 5
  4. 6

10) What will be the output of following program?
public class temp
{
	public static void main(String agrs[])
	{
		int loop;
		
		for(loop=1; loop<=10; loop++)
		{
			loop*=2;
			if(loop>12)
				break;
		}
		System.out.println(loop);
	}
}
  1. 11
  2. 12
  3. 13
  4. 14








Comments and Discussions!

Load comments ↻






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