Advertisement
ZornTaov

Diamond maker

Oct 1st, 2011
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.71 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Diamond
  4. {
  5.     public static void main(String[] args)
  6.     {
  7.     int numStars;
  8.     Scanner input = new Scanner(System.in);
  9.     numStars = input.nextInt(); // obtain user input
  10.     int middle = numStars / 2 + 1;
  11.     int columnWidth = numStars / 2;
  12.     int numSpaces = columnWidth;
  13.     int rowCntr;
  14.     int colCntr;
  15.     boolean leftRight = true;// true = left
  16.     boolean topBottom = true;// true = top
  17.     for (rowCntr = 1; rowCntr <= numStars; rowCntr++)
  18.     {
  19.         if (rowCntr < middle)
  20.         {
  21.         numSpaces = columnWidth - rowCntr;
  22.         }
  23.         else if (rowCntr == middle)
  24.         {
  25.         numSpaces = 0;
  26.         topBottom = false;
  27.         }
  28.         else
  29.         {
  30.         numSpaces++;
  31.         }
  32.         for (colCntr = 1; colCntr <= numStars; colCntr++)
  33.         {
  34.         if (topBottom)
  35.         {
  36.             if (colCntr <= numSpaces + 1)
  37.             {
  38.             System.out.print("a");
  39.             }
  40.             else if (colCntr == middle)
  41.             {
  42.             System.out.print("b");
  43.             leftRight = false;
  44.             }
  45.  
  46.             else if (!leftRight && (numStars - colCntr) <= numSpaces)
  47.             {
  48.             System.out.print("c");
  49.             }
  50.             else
  51.             {
  52.             System.out.print("d");
  53.             }
  54.  
  55.         }
  56.         else if (rowCntr == middle)
  57.         {
  58.             System.out.print("e");
  59.         }
  60.         else if (!topBottom)
  61.         {
  62.             if (colCntr <= numSpaces)
  63.             {
  64.             System.out.print("f");
  65.             }
  66.             else if (colCntr == middle)
  67.             {
  68.             System.out.print("g");
  69.             leftRight = false;
  70.             }
  71.  
  72.             else if (!leftRight && (numStars - colCntr) <= numSpaces)
  73.             {
  74.             System.out.print("h");
  75.             }
  76.             else
  77.             {
  78.             System.out.print("i");
  79.             }
  80.  
  81.         }
  82.         // else if(!topBottom)
  83.         // {
  84.  
  85.         // }
  86.         }// end colCntr
  87.         System.out.println();
  88.         leftRight = true;
  89.     }// end rowCntr
  90.     }
  91.  
  92. }
  93.  
  94.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement