AIM: Java program to print star pattern using for, while and do-while Loops.
PROGRAM:
import java.util.Scanner;
public class LoopDemo
public static void main(String[] args)
Scanner sc = new Scanner(System.in);
System.out.print("Enter number of rows: ");
int rows = sc.nextInt();
System.out.println("\nStar Pattern using for loop:");
for (int i = 1; i <= rows; i++)
for (int j = 1; j <= i; j++)
System.out.print("* ");
System.out.println();
System.out.println("\nStar Pattern using while loop:");
int i = 1;
while (i <= rows)
int j = 1;
while (j <= i)
{System.out.print("* ");
j++;
System.out.println();
i++;
}
System.out.println("\nStar Pattern using do-while loop:");
i = 1;
do
int j = 1;
do
System.out.print("* ");
j++;
} while (j <= i);
System.out.println();
i++;
} while (i <= rows);
sc.close();
OUTPUT: