Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class GeorgeHany {
- public static void main (String [] args){
- Scanner sc = new Scanner (System.in);
- System.out.print("Enter a positive odd number: ");
- int n = sc.nextInt();
- if (n == 1){
- System.out.println("*");
- }
- else {
- int c = n/2 + 1;
- for (int i=1; i<c; i++)
- System.out.print(" ");
- System.out.println("*");
- int spaces1 = c - 2;
- int spaces2 = 0;
- for (int i=2; i<c; i++){
- for (int j=1; j<=spaces1; j++)
- System.out.print(" ");
- System.out.print("*");
- for (int j=1; j<=spaces2; j++)
- System.out.print(" ");
- System.out.print("*");
- for (int j=1; j<=spaces2; j++)
- System.out.print(" ");
- System.out.println("*");
- spaces1--;
- spaces2++;
- }
- for (int i=1; i<=n; i++)
- System.out.print("*");
- System.out.println("");
- spaces1 = 1;
- spaces2 = c - 3;
- for (int i=2; i<c; i++){
- for (int j=1; j<=spaces1; j++)
- System.out.print(" ");
- System.out.print("*");
- for (int j=1; j<=spaces2; j++)
- System.out.print(" ");
- System.out.print("*");
- for (int j=1; j<=spaces2; j++)
- System.out.print(" ");
- System.out.println("*");
- spaces1++;
- spaces2--;
- }
- for (int i=1; i<c; i++)
- System.out.print(" ");
- System.out.print("*");
- }
- }
- }
Add Comment
Please, Sign In to add comment