Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Bara {
- public static void main (String [] args){
- Scanner sc = new Scanner(System.in);
- System.out.print("Enter the size of the diamond: ");
- int n = sc.nextInt();
- for (int line = 1; line <= n; line++){
- String output = "";
- if ((line == 1)||(line == n)){
- for (int i = 1; i <= n / 2; i++)
- output += " ";
- output += "*";
- }
- else {
- if (line == n/2 + 1){
- for (int i = 1; i <= n; i++)
- output += "*";
- }
- else {
- String s1 = "";
- String s2 = "";
- int mid = n/2 + 1;
- int x = line;
- if (x > mid)
- x = n+1-x;
- for (int i = 1; i <= mid-x; i++)
- s1 += " ";
- for (int i = mid-x+2; i<mid; i++)
- s2 += " ";
- output = s1 + "*" + s2 + "*" + s2 +"*" + s1;
- }
- }
- System.out.println(output);
- }
- }
- }
Add Comment
Please, Sign In to add comment