Computer Applications
Give the output of the following Java program snippet based on nested loops:
int a,b;
for (a=1; a<=2; a++)
{
for (b= (64+a); b<=70; b++)
System.out.print((char) b);
System.out.println( );
}
Java
Java Nested for Loops
91 Likes
Answer
ABCDEF BCDEF
Working
In the first iteration of outer for loop, the inner for loop will print characters with ASCII codes from 65 to 70 i.e. letters from A to F.
In the second iteration of outer for loop, the inner for loop will print characters with ASCII codes from 66 to 70 i.e. letters from B to F.
Answered By
38 Likes
Related Questions
Give the output of the following Java program snippet based on nested loops:
int i,j; for (i=0; i<4; i++) { for (j=i; j>=0; j--) System.out.print(j); System.out.println(); }
Give the output of the following Java program snippet based on nested loops:
int i,j; first: for (i=10; i>=5; i--) { for (j= 5; j<=i; j++) { if (i*j <40) continue first; System.out.print(j); } System.out.println( ); }
Give the output of the following Java program snippet based on nested loops:
int x,y; for(x=1; x<=5; x++) { for(y=1; y<x; y++) { if(x == 4) break; System.out.print(y); } System.out.println( ); }
Give the output of the following Java program snippet based on nested loops:
int y,p; for (int x=1; x<=3; x++) { for (y=1; y<=2; y++) { p = x * y; System.out.print(p); } System.out.println( ); }