Advertisement
Guest User

Untitled

a guest
Oct 13th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1.  
  2. import java.util.Scanner;
  3.  
  4.  
  5.  
  6. public class P {
  7.  
  8. public static void main(String[] args) {
  9. int size;
  10. String c;
  11.  
  12. Scanner scan = new Scanner(System.in);
  13. print("Please Enter size of Parallelagram: ");
  14. size = scan.nextInt();
  15. println("");
  16.  
  17. //removes \n buffer
  18. scan.nextLine();
  19.  
  20. print("Please Enter the Character: ");
  21. c = scan.nextLine();
  22.  
  23. makePolygon(size,c);
  24. }
  25.  
  26. public static void makePolygon(int size, String str) {
  27. makePolygonTop(size,str);
  28. makePolygonBottom(size,str);
  29. }
  30.  
  31.  
  32. //Makes hallow Top
  33. public static void makePolygonTop(int size, String str) {
  34. for(int i=0;i<size;i++) {
  35. for(int j=0; j<=i;j++) {
  36.  
  37. if(j==0 || j == i)
  38. print(str);
  39. else
  40. print(" ");
  41. }
  42. println("");
  43. }
  44. }
  45.  
  46. //Makes hallow bottom
  47. public static void makePolygonBottom(int size, String str) {
  48.  
  49. for(int i=1;i<size;i++) {
  50. for(int j=0; j<size;j++) {
  51.  
  52. if(j<i || j>i && j< size-1)
  53. print(" ");
  54. else
  55. print(str);
  56. }
  57. println("");
  58. }
  59. }
  60.  
  61. public static void println(String str) {
  62. System.out.println(str);
  63. }
  64. public static void print(String str) {
  65. System.out.print(str);
  66. }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement