JAVA Pyramids 2
In the
previous post we have discussed about different pyramids examples and we will continue to do some more examples. In this tutorial I will post the code of some more complex pyramid examples.
*
***
*****
*******
********* |
Code for this program:-
import java.util.Scanner;
public class Pyramid {
public static void main(String[] args) {
System.out.println("Enter the length of pyramid");
Scanner scan = new Scanner(System.in);
int rows = scan.nextInt();
System.out.println("-------Output------");
for (int i = 1; i <= rows; i++) {
for (int j = rows-1; j >= i; j--) {
System.out.print(" ");
}
for (int k = 1; k <= i; k++) {
System.out.print("*");
}
for (int l = 2; l <= i; l++) {
System.out.print("*");
}
System.out.println();
}
System.out.println("-------------------");
}
}
|
Output of Program:-
************
***** *****
**** ****
*** ***
** **
* * |
Code for this Program:-
import java.util.Scanner;
public class Pyramid {
public static void main(String[] args) {
System.out.println("Enter the length of pyramid");
Scanner scan = new Scanner(System.in);
int rows = scan.nextInt();
System.out.println("-------Output------");
for (int i = 1; i <= rows; i++) {
for (int j = rows; j >= i; j--) {
System.out.print("*");
}
for (int k = 2; k <= i; k++) {
System.out.print(" ");
}
for (int l = rows; l >= i; l--) {
System.out.print("*");
}
System.out.println();
}
System.out.println("-------------------");
}
} |
Output of Program:-
************
***** *****
**** ****
*** ***
** **
* *
* *
** **
*** ***
**** ****
***** *****
************ |
Code for this Program:-
Thank for your help and make it many program
ReplyDelete