In the program the following star pattern will be
printed.
At first, we get the number where we want to print
the star pattern from the user with the use of Scanner class and store that
number in variable n then we make a loop which starts from 0 till n-1.
Inside of that loop there is another loop from 0 to
n-1 and we jump from the inner loop if we get a number greater than the outer
loop value with the use of continue because we only want stars equal to outer
loops in a single line.
The program is shown below :
1: import java.util.Scanner;
2:
3: class StarPattern1
4: {
5: public static void main(String[] args)
6: {
7: int n;
8: System.out.println("Enter the number till you want a star pattern");
9: Scanner scan = new Scanner(System.in);
10: n = scan.nextInt();
11:
12: label: for(int i=0; i<n; i++)
13: {
14: for(int j=0; j<n; j++)
15: {
16: if(j>i)
17: {
18: System.out.println();
19: continue label;
20: }
21: else
22: {
23: System.out.print("*");
24: }
25: }
26: }
27: }
28: }








