Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

package homeWork;

import java.util.*;
public class StarPattern {

public static void main(String[] args) {


// TODO Auto-generated method stub
Scanner sc=new Scanner(System.in);
System.out.println("Enter the number");
int a=sc.nextInt();
sc.close();
int b=1,c=a-2;
if(a%2!=0) {
System.out.println("The pattern is,");
while(b<=a) {
for(int j=0;j<c;j++)
System.out.printf(" ");
for(int i=1;i<=b;i++)
System.out.printf("%s",i);
System.out.println("");
b+=2; c--;
}
b=a-2; c+=2;
while(b>=1) {
for(int j=0;j<c;j++)
System.out.print(" ");
for(int i=1;i<=b;i++)
System.out.printf("%s",i);
System.out.println("");
b=b-2; c++;
}

}
else
System.out.println("Enter an odd number");
}
}

You might also like