Programs for printing pyramid patterns in Java


import java.util.Scanner;

public class First2 {

public void p1() {
Scanner sc = new Scanner(System.in);
int row = sc.nextInt();
for (int i = 1; i <= row; i++) {
for (int j = i; j < row; j++) {
System.out.print(" ");
}
for (int j = 1; j <= 2 * i - 1; j++) {
System.out.print("*");
}
System.out.println();
}

}

public void p2() {
Scanner sc = new Scanner(System.in);
int rows1 = sc.nextInt();
for (int i = 1; i <= rows1; i++) {
for (int j = i; j < rows1; j++) {
System.out.print(" ");
}
for (int j = 1; j <= (2 * i - 1); j++) {
System.out.print("*");
}

System.out.println();

}
for (int i = rows1; i >= 1; i--) {
for (int j = i; j < rows1; j++) {
System.out.print(" ");
}
for (int j = 1; j <= (2 * i - 1); j++) {
System.out.print("*");
}

System.out.println();

}

}

public void p3() {
Scanner sc = new Scanner(System.in);
int row = sc.nextInt();
for (int i = 1; i <= row; i++) {
for (int j = i; j < row; j++) {
System.out.print(" ");
}
for (int k = 1; k <= 2 * i - 1; k++) {
System.out.print("*");
}

System.out.println();
}
}

public static void main(String[] args) {
First2 f = new First2();
f.p1();
f.p2();
f.p3();
// f.ArithError();

}
}


output
-------------
3
  *
 ***
*****
4
   *
  ***
 *****
*******
*******
 *****
  ***
   *

5
    *
   ***
  *****
 *******
*********

Post a Comment

8 Comments

  1. This comment has been removed by the author.

    ReplyDelete
  2. I recently found many useful information in your website especially this blog page. Among the lots of comments on your articles. Thanks for sharing. הדפסות על חולצות חולון

    ReplyDelete
  3. I wanted to thank you for this in your liking ensnare!! I particularly enjoying all tiny little bit of it I have you ever bookmarked to check out delivered stuff you pronounce. Letterhead Printing

    ReplyDelete
  4. While GPS coupons may appear to be a fantastic component for organizations that need to build foot exchange, they won't fill in too for organizations that require appearance by arrangement as it were.토토먹튀

    ReplyDelete
  5. I am eager the set up. It is wonderful to determine many people explain in words from your nature as well as capability upon which basic subject region are usually easily discovered. printers new orleans

    ReplyDelete
  6. They offer day in and day out free specialized help which is best in class. On the off chance that you ever have any inquiries or issues, you can get in touch with them with any specialized inquiries.7zip

    ReplyDelete
  7. After examine a number of of the blog posts in your web site now, and I truly like your way of blogging. I bookmarked it to my bookmark website listing and might be checking back soon. Pls check out my web site as well and let me know what you think. informasi percetakan

    ReplyDelete
  8. This is actually intriguing, You’re an exceptionally effective blogger. I’ve enrolled with your feed and furthermore , look ahead to reading your marvelous write-ups. What’s more, We have shared your internet site inside our social networks. you can try this out

    ReplyDelete
Emoji
(y)
:)
:(
hihi
:-)
:D
=D
:-d
;(
;-(
@-)
:P
:o
:>)
(o)
:p
(p)
:-s
(m)
8-)
:-t
:-b
b-(
:-#
=p~
x-)
(k)