Write a java program to display the following patterns.
Input: 5
Output:
*
***
*****
*******
*********
import java.io.*; import java.util.*; public class temp { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int a,n; System.out.println("Enter a number: "); a = scan.nextInt(); n = a*2; for(int i = 0; i<=n; i++){ if (i%2 == 0) continue; for(int j = 1; j<=i;j++){ System.out.print("*"); } System.out.println(); } } }
INPUT_1:
Enter a number:
5
OUTPUT:
*
***
*****
*******
*********
INPUT_2:
Enter a number:
4
OUTPUT:
*
***
*****
*******
INPUT_3:
Enter a number:
6
OUTPUT:
*
***
*****
*******
*********
***********
INPUT_4:
Enter a number:
7
OUTPUT:
*
***
*****
*******
*********
***********
*************
INPUT_5:
Enter a number:
9
OUTPUT:
*
***
*****
*******
*********
***********
*************
***************
*****************
INPUT_6:
Enter a number:
15
OUTPUT:
*
***
*****
*******
*********
***********
*************
***************
*****************
*******************
*********************
***********************
*************************
***************************
*****************************
ILLUSTRATION