I am answering a question for an Intro to Programming class and cannot - after reading through my notes, Big Java book, and looking online - find out where to begin.
It seems as though it should be very simple, but I just need to get started. All of this is for Java and is being worked on in Eclipse.
The task is to take in a name ("Name") and a number (int x) and display the "Name" x number of times on one line, x-1 times on another line, and so on and so on until you display the name only once. It seems like it should be a reverse accumulator, but I'm having trouble starting my method. How do I begin? I know I can't multiply strings in Java like you can in python or other languages, but how can I print the "Name" x number of times without building an Array or inputing
System.out.println("name" + " " + "name" + " "...).
Any suggestions are appreciated. I am a novice at this. Thank you!
You need a loop, a common feature of programming languages.
Have a close look at the java for
loop.
Additional hint:
System.out.println("test")
prints it's argument in a single line while System.out.print("test")
doesn't add a CR/LF
after test
.