   Java -- Basic Algorithm question
  Hey all,I know the rule 'won't answer homework' questions, and that's fine. Don't tell me (but help :)), but I'm ALMOST THERE but can't quite figure the nearingly (almost) last part of this 'algorithm'.Problem ::  display a diamond (the row number of a diamond must be odd) of asterisks whose row is specified in an integer parameter row. For example, if row is 7, the method displays the pattern of asterisks at the top of the next page.   * ********    ************ ***  *I'll be upset if some students google's that question for homework and finds it! (is there a tag that stops a search engine from tagging?)Here is what I've managed so far, and it's SO CLOSE. The triangle comes out like this... ****    *****   ************    ****public class Main{    public static void main(String[] args)    {   showmezedisamondplz(7); // must be odd number!!!    }   public static void showmezedisamondplz(int rows)    {   //is rows odd or even?   if ((rows % 2) != 0)   {  //is odd  ++rows;   }   else   {  //is even  return;   }   //display the top of the diamond   for (int mainloop = 0; mainloop < rows; ++mainloop)   {  //only show every other line of the diamond  if ((mainloop % 2) != 0)  { //display how many spaces for (int spaces = ((mainloop - rows) / 2); spaces < rows; ++spaces) {System.out.print(" "); } //display how many asterisks for (int display = 0; display < (mainloop % rows); ++display) {System.out.print("*"); } //determine if we should printline or not if (mainloop < (rows - 1)) {System.out.println();System.out.println(); }  }   } //display the bottom of the diamond   int reverse = rows;  for (int mainloop = 0; mainloop < rows; ++mainloop)  { //only show every other line of the diamond if (reverse % 2 != 0) { //display how many spaces for (int spaces = ((reverse - rows) / 2); spaces < rows; ++spaces) {System.out.print(" "); }  //display how many asterisks for (int display = 0; display < (reverse % rows); ++display) {System.out.print("*"); } --reverse; //determine if we should printline or not if (mainloop < (rows + 1)) {System.out.println();System.out.println(); } }  else --reverse;   }   // return rows to its initial value   ++rows;   }    }Thanks![Edited by - 3shirtlessmen on May 7, 2009 5:16:09 PM]
  How many spaces do you need to print in the middle line?How many in the previous one?How many in the next to the middle one?[...]How many in line (middle - n)?How many in line (middle + n)?Answer this questions and look for a pattern!;  I've thought about it more and made appropriate changes but the spacing is just **ONE** off??!! How?I'll keep looking but if anyone has hints I'm all ears. :)   ;  Sorry, I hadn't correctly seen your second diamond.You just have to print an extra space in each row for the lower triangle (quite obvious, I know). So where's the problem?I think just changing a < with <= will do the trick.;  I got it working -- Thanks!   