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
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)
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.
Originally Posted by Cubba27