You are here : Home / Core Java Tutorials / Interview Programs (beginner to advanced) in java / Pattern/Pyramid generating programs in java
Write a program to generate this Pattern.
Full Program/SourceCode >
package pyramid;
import java.util.Scanner;
/** Copyright (c), AnkitMittal JavaMadeSoEasy.com */
public class Pyramid12 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter n : ");
int n = scanner.nextInt();
System.out.println("");
for (int i = 1; i <= n; i++) {
int k=i;
for (int j = 1; j <= n; j++) {
System.out.print((j<= n-i ? " " : k--));
}
System.out.println();
}
}
}
/*OUTPUT
Enter n : 5
1
21
321
4321
54321
*/
|
Having any doubt? or you you liked the tutorial! Please comment in below section.
Please express your love by liking JavaMadeSoEasy.com (JMSE) on facebook, following on google+ or Twitter.
RELATED LINKS>