Guest User

Untitled

a guest
Jul 17th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.84 KB | None | 0 0
  1. import java.util.*;
  2. public class Bara {
  3.     public static void main (String [] args){
  4.         Scanner sc = new Scanner(System.in);
  5.         System.out.print("Enter the size of the diamond: ");
  6.         int n = sc.nextInt();
  7.         for (int line = 1; line <= n; line++){
  8.             String output = "";
  9.            
  10.             if ((line == 1)||(line == n)){
  11.                 for (int i = 1; i <= n / 2; i++)
  12.                         output += " ";
  13.                 output += "*";
  14.             }
  15.             else {
  16.                 if (line == n/2 + 1){
  17.                     for (int i = 1; i <= n; i++)
  18.                     output += "*";
  19.                 }
  20.                 else {
  21.                     String s1 = "";
  22.                     String s2 = "";
  23.                     int mid = n/2 + 1;
  24.                     int x = line;
  25.                     if (x > mid)
  26.                         x = n+1-x;
  27.                     for (int i = 1; i <= mid-x; i++)
  28.                         s1 += " ";
  29.                     for (int i = mid-x+2; i<mid; i++)
  30.                         s2 += " ";
  31.                     output = s1 + "*" + s2 + "*" + s2 +"*" + s1;
  32.                 }
  33.             }
  34.             System.out.println(output);
  35.         }
  36.     }
  37. }
Add Comment
Please, Sign In to add comment