Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class P {
- public static void main(String[] args) {
- int size;
- String c;
- Scanner scan = new Scanner(System.in);
- print("Please Enter size of Parallelagram: ");
- size = scan.nextInt();
- println("");
- //removes \n buffer
- scan.nextLine();
- print("Please Enter the Character: ");
- c = scan.nextLine();
- makePolygon(size,c);
- }
- public static void makePolygon(int size, String str) {
- makePolygonTop(size,str);
- makePolygonBottom(size,str);
- }
- //Makes hallow Top
- public static void makePolygonTop(int size, String str) {
- for(int i=0;i<size;i++) {
- for(int j=0; j<=i;j++) {
- if(j==0 || j == i)
- print(str);
- else
- print(" ");
- }
- println("");
- }
- }
- //Makes hallow bottom
- public static void makePolygonBottom(int size, String str) {
- for(int i=1;i<size;i++) {
- for(int j=0; j<size;j++) {
- if(j<i || j>i && j< size-1)
- print(" ");
- else
- print(str);
- }
- println("");
- }
- }
- public static void println(String str) {
- System.out.println(str);
- }
- public static void print(String str) {
- System.out.print(str);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement