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

Sachin Exp 2 Java

Uploaded by

kushaldubey121
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)
13 views2 pages

Sachin Exp 2 Java

Uploaded by

kushaldubey121
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

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:

You might also like