Results 1 to 4 of 4
Thread: Diamond Program?????
- 11-19-2009, 07:59 PM #1
Member
- Join Date
- Nov 2009
- Posts
- 12
- Rep Power
- 0
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
- 11-19-2009, 08:02 PM #2
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.
- 11-19-2009, 08:10 PM #3
Member
- Join Date
- Nov 2009
- Posts
- 12
- Rep Power
- 0
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 :/
- 11-19-2009, 08:15 PM #4
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
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
-
changing my program to array working program
By Chewart in forum New To JavaReplies: 39Last Post: 11-18-2009, 06:53 PM -
Execute A program from a Program!
By Moncleared in forum Advanced JavaReplies: 2Last Post: 02-22-2009, 04:17 PM -
Executing a program within a program
By gibsonrocker800 in forum New To JavaReplies: 5Last Post: 05-12-2008, 08:24 AM -
How to execute an External Program through Java program
By Java Tip in forum java.ioReplies: 0Last Post: 04-04-2008, 02:40 PM -
How to execute an External Program through Java program
By JavaBean in forum Java TipReplies: 0Last Post: 10-04-2007, 09:33 PM
Bookmarks