Results 1 to 4 of 4
  1. #1
    Cubba27 is offline Member
    Join Date
    Nov 2009
    Posts
    12
    Rep Power
    0

    Default Diamond Program?????

    Hey all, i'm new to java and i've been set a task... but i can't work this out for the life of me. i understand the concepts of loops, and the scanner class fine and i can implement them in basic programs. anyhow the problems is as follows:

    The program displays a diamond pattern to the screen. The size of the pattern is determined by an integer value which is supplied by the user at runtime. The number must be in the range 1 to 10. If the number is outside the range the program will prompt the used to enter a valid number (see: example three). When a valid number is entered the pattern is generated, each side of the diamond has exactly the same number of * as the user entered, see blow for examples.
    The user input should be via the Scanner class, you should not use either JOptionPane or Integer.parseInt() to solve this problem.
    Your program should contain a while or do..while loop, as well and at least one nested for loop.

    any help on this would be great

  2. #2
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    6

    Default

    What exactly are you stuck on? You said you understand loops and the scanner class so why not start by throwing together a little skeleton of what the program should do(or at least get it reading in and accepting the user input first)
    Liberty has never come from the government.
    Liberty has always come from the subjects of government.
    The history of liberty is the history of resistance.
    The history of liberty is a history of the limitation of governmental power, not the increase of it.

  3. #3
    Cubba27 is offline Member
    Join Date
    Nov 2009
    Posts
    12
    Rep Power
    0

    Default

    i've been hacking code, and trying to put this thing together for a good week and a bit now. i just don't know what it is. the best i've been able to come up with is my scanner class accepting a int and then printing a string. same with the loops best i've come up with is getting them to print out a string. I know that within the for loops there should be other for loops.... i just can't figure it out :/

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,336
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by Cubba27 View Post
    i've been hacking code, and trying to put this thing together for a good week and a bit now. i just don't know what it is. the best i've been able to come up with is my scanner class accepting a int and then printing a string. same with the loops best i've come up with is getting them to print out a string. I know that within the for loops there should be other for loops.... i just can't figure it out :/
    Try to design two small methods: the first one is supposed to write n spaces where n is given as a parameter; the second one is supposed to write m stars where m is given as a parameter. The first method is not allowed to advance to the next line while your second method is allowed to do so (but it is not mandatory). Given those two little methods try to describe a loop that describes a diamond shape figure. Keep those two little methods for later.

    kind regards,

    Jos

Similar Threads

  1. changing my program to array working program
    By Chewart in forum New To Java
    Replies: 39
    Last Post: 11-18-2009, 06:53 PM
  2. Execute A program from a Program!
    By Moncleared in forum Advanced Java
    Replies: 2
    Last Post: 02-22-2009, 04:17 PM
  3. Executing a program within a program
    By gibsonrocker800 in forum New To Java
    Replies: 5
    Last Post: 05-12-2008, 08:24 AM
  4. Replies: 0
    Last Post: 04-04-2008, 02:40 PM
  5. Replies: 0
    Last Post: 10-04-2007, 09:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •