ADVERTISEMENT
ADVERTISEMENT

Java Control (Looping) Statements Aptitude Questions and Answers.

This section contains Aptitude Questions and Answers on Java Control Statements (Looping) like for, do while, while and for each with explanation.

List of Control (Loop) Statements Aptitude Questions

1) What is the correct syntax of for each loop?
  1. for(variable:collection)
     {body;}
  2. for(data_type variable:collection)
     {body;}
  3. for(variable;collection)
     {body;}
  4. for(data_type variable;collection)
     {body;}

2) Is following code snippet is correct?
for(int i=1; i<=10; i++)
	System.out.println(i);
  1. Yes
  2. No

3) What will be the output of following program?
public class temp
{
	public static void main(String agrs[])
	{
		for(int i=1; i<=10; i++);
		System.out.print(i);
	}
}
  1. 12345678910
  2. 11
  3. Error
  4. 1 2 3 4 5 6 7 8 9 10

4) What will be the output of following program?
public class temp
{
	public static void main(String agrs[])
	{
		int i;
		for(i=1; i<=10; i++);
		System.out.print(i);
	}
}
  1. 12345678910
  2. 11
  3. Error
  4. 1 2 3 4 5 6 7 8 9 10

5) What will be the output of following program?
public class temp
{
	public static void main(String agrs[])
	{
		int x[]={1,2,3,4,5};
		for(int i=0; i<x.length;i++)
			System.out.print(x[i]);
	}
}
  1. Error – length is not a method of x.
  2. 6
  3. 1,2,3,4,5
  4. 12345





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.