help please

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jshwille7688
    New Member
    • Mar 2008
    • 2

    help please

    I have this assignment it prints out to a window but it all print out on 1 line

    it should be in shape of a diamond but it looks like this:
    **** *
    import avi.*;

    public class diamonds
    {
    public static void main(String[] args)
    {
    Window screen = new Window("diamond s.java","bold", "blue",18);
    screen.showWind ow();

    int max_width;
    DialogBox inputMax_width= new DialogBox(scree n,"Enter an odd number, 1 or more!");
    inputMax_width. showDialogBox() ;
    max_width = inputMax_width. getInteger();

    int width=max_width % 2 == 0? max_width/2: max_width/2 +1;
    String stars="******** *************** *************** ********";
    String spaces=" ";
    for ( int i=1; i<(width*2); i++ )
    {
    screen.write( spaces.substrin g(0, (i < width ? width -i : i%width)));
    screen.write(st ars.substring(0 ,2*(i<=width? i : width-(i%width))-1 ));
    }
    }
    }
  • sukatoa
    Contributor
    • Nov 2007
    • 539

    #2
    Originally posted by jshwille7688
    I have this assignment it prints out to a window but it all print out on 1 line

    it should be in shape of a diamond but it looks like this:
    **** *
    import avi.*;

    public class diamonds
    {
    public static void main(String[] args)
    {
    Window screen = new Window("diamond s.java","bold", "blue",18);
    screen.showWind ow();

    int max_width;
    DialogBox inputMax_width= new DialogBox(scree n,"Enter an odd number, 1 or more!");
    inputMax_width. showDialogBox() ;
    max_width = inputMax_width. getInteger();

    int width=max_width % 2 == 0? max_width/2: max_width/2 +1;
    String stars="******** *************** *************** ********";
    String spaces=" ";
    for ( int i=1; i<(width*2); i++ )
    {
    screen.write( spaces.substrin g(0, (i < width ? width -i : i%width)));
    screen.write(st ars.substring(0 ,2*(i<=width? i : width-(i%width))-1 ));
    }
    }
    }
    you can read this
    . You might get some idea there....

    hope it helps,
    sukatoa

    Comment

    • jshwille7688
      New Member
      • Mar 2008
      • 2

      #3
      ok i dropped the idea of having the diamond in the window and i was wondering if i some how could decide on any symbol besides the * heres my new code:

      public class diamonds
      {
      public static void main(String[] args)
      {
      int max_width = new Integer(args[0]).intValue();
      int width=max_width % 2 == 0? max_width/2: max_width/2 +1;
      String symbols="****** *************** *************** **********";
      String spaces=" ";
      for ( int i=1; i<(width*2); i++ ) {
      System.out.prin t(spaces.substr ing(0, (i < width ? width -i : i%width)));
      System.out.prin tln(symbols.sub string(0,2*(i<= width? i : width-(i%width))-1 ));
      }

      }
      }

      Comment

      Working...