Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Diamond
- {
- public static void main(String[] args)
- {
- int numStars;
- Scanner input = new Scanner(System.in);
- numStars = input.nextInt(); // obtain user input
- int middle = numStars / 2 + 1;
- int columnWidth = numStars / 2;
- int numSpaces = columnWidth;
- int rowCntr;
- int colCntr;
- boolean leftRight = true;// true = left
- boolean topBottom = true;// true = top
- for (rowCntr = 1; rowCntr <= numStars; rowCntr++)
- {
- if (rowCntr < middle)
- {
- numSpaces = columnWidth - rowCntr;
- }
- else if (rowCntr == middle)
- {
- numSpaces = 0;
- topBottom = false;
- }
- else
- {
- numSpaces++;
- }
- for (colCntr = 1; colCntr <= numStars; colCntr++)
- {
- if (topBottom)
- {
- if (colCntr <= numSpaces + 1)
- {
- System.out.print("a");
- }
- else if (colCntr == middle)
- {
- System.out.print("b");
- leftRight = false;
- }
- else if (!leftRight && (numStars - colCntr) <= numSpaces)
- {
- System.out.print("c");
- }
- else
- {
- System.out.print("d");
- }
- }
- else if (rowCntr == middle)
- {
- System.out.print("e");
- }
- else if (!topBottom)
- {
- if (colCntr <= numSpaces)
- {
- System.out.print("f");
- }
- else if (colCntr == middle)
- {
- System.out.print("g");
- leftRight = false;
- }
- else if (!leftRight && (numStars - colCntr) <= numSpaces)
- {
- System.out.print("h");
- }
- else
- {
- System.out.print("i");
- }
- }
- // else if(!topBottom)
- // {
- // }
- }// end colCntr
- System.out.println();
- leftRight = true;
- }// end rowCntr
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement