0% found this document useful (0 votes)
6 views2 pages

Class IX - Nested Loop - Program 04 (Pattern 04)

The document provides a Java program to display a specific pattern using nested loops. The pattern consists of letters from A to E, where each letter is printed multiple times corresponding to its position in the sequence. It includes the code, output, and a dry run explanation of how the loops operate to generate the pattern.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views2 pages

Class IX - Nested Loop - Program 04 (Pattern 04)

The document provides a Java program to display a specific pattern using nested loops. The pattern consists of letters from A to E, where each letter is printed multiple times corresponding to its position in the sequence. It includes the code, output, and a dry run explanation of how the loops operate to generate the pattern.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

K.E.

CARMEL SCHOOL, AMTALA


COMPUTER
CLASS–IX NESTED LOOP PROGRAM–04

Nested Loop 04
Write a program in Java to display the following pattern :
A
B B
C C C
D D D D
E E E E E

Code
import java.io.*;
import java.lang.*;
import java.util.*;
class Pattern4
{
public static void main(String args[ ])
{
for(char i='A'; i<='E'; i++)
{
for(char j='A'; j<=i; j++)
{
System.out.print(i + "\t");
}// end of inner for
System.out.println( );
}// end of outer for
}// end of main
}// end of class

Output
Dry Run
for(char i='A'; i<='E'; i++)
for(char j='A'; j<=i; j++)

Initially, the pattern will be printed up to ‘E’

i=A, A<=E True, j=A, A<=A True Print A


j=B, B<=A False, inner for loop ends.

i=B, B<=E True, j=A, A<=B True Print B


j=B, B<=B True Print B B
j=C, C<=B False, inner for loop ends.

i=C, C<=E True, j=A, A<=C True Print C

You might also like