Skip to content

Instantly share code, notes, and snippets.

@sagardere
Created May 23, 2018 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sagardere/af49eb966b445ca53019a44883565ff5 to your computer and use it in GitHub Desktop.
Save sagardere/af49eb966b445ca53019a44883565ff5 to your computer and use it in GitHub Desktop.
import java.util.Scanner;
public class pattern {
public static void printTriagle(int n)
{
int temp = n;
for(int i=0;i<n;i++) {
for(int j=0;j<n*2;j++) {
if(i==0) {
System.out.print(n);
} else if ((j<n-i) || (j>=temp+(i*2))) {
System.out.print(temp);
} else {
System.out.print("*");
}
}
temp--;
System.out.println("");
}
}
public static void main(String[] args) {
pattern obj=new pattern();
Scanner sc=new Scanner(System.in);
System.out.println("Enter the value of n : ");
int n = sc.nextInt();
obj.printTriagle(n);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment