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);
	}
}
        
            - 1122334455
- 12345
- 11223344
- Error
           Correct Answer: 4
           Error
           Consider this statement int i=1, int j=1 we can not declare variables like that. Correct form is int i=1,j=1 correct loop statement is: for(int i=1,j=1; i<5; i++,j++)
         
    
      
        
        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);
	}
}
        
            - 1122334455
- 12345
- 11223344
- Error
        Correct Answer: 3
        11223344
         
    
      
        
        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);
        
            - 2468
- 12345
- 11223344
- Error
        Correct Answer: 1
        2468
        In the statement System.out.print(i+j); the expression in i+j, both are integer values and return addition.
         
    
      
        
        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;
}
        
            - 3
- 4
- 5
- 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);
	}
}
        
            - 11
- 12
- 13
- 14