{}
BLACK NOVEMBER
Get 83% off PRO
Are you struggling to build your coding confidence or land your first job?
Fast-track to your first pay-check.
Start FREE trial →
Start FREE trial →
BLACK NOVEMBER
Get 83% off PRO
Are you struggling to build your coding confidence or land your first job?
Fast-track to your first pay-check.
Start FREE trial →
Start FREE trial →
run-icon
Main.java
import java.util.*; class Pattern{ public static void main(String[] args){ Scanner sc =new Scanner(System.in); System.out.println("enter no. of row="); int n=sc.nextInt(); for(int i=1; i<=n; i++){ for(int j=1; j<=i; j++){ if(j==1 || i==j) System.out.print("*"+" "); else System.out.print(" "+" "); } for(int j=1; j<=2*(n-i); j++){ System.out.print(" "+" "); } for(int j=1; j<=i; j++){ if(j==1 || i==j) System.out.print("*"+" "); else System.out.print(" "+" "); } System.out.println(); } for(int i=n; i>=1; i--){ for(int j=1; j<=i; j++){ if(j==1 || j==i) System.out.print("*"+" "); else System.out.print(" "+" "); } for(int j=1; j<=2*(n-i); j++){ System.out.print(" "+" "); } for(int j=1; j<=i; j++){ if(j==1 || i==j) System.out.print("*"+" "); else System.out.print(" "+" "); } System.out.println(); } } }
Output