ADVERTISEMENT
ADVERTISEMENT

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





ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions


ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.