0

I am needing to write a program for someone that needs it to count by any number they manually enter into the program. I have the menu code written and now just need help with the counnting code. I know i most likely need to use a "for" loop but after that i am not sure.

5
Contributors
5
Replies
14
Views
6 Years
Discussion Span
Last Post by Slavi
0

that's easy just put while loop that has a number in it then print the number then put an empty for loop and then add 5 to the number then repaint/ redraw the number and continue. it should look something like this:

int a = 0;
while (a == 0){
int num = 0;
for (int i = 0; i <= enter a number here that suits your delay; i++);
num += userEnteredNumber;
//repaint/set text etc.
}

Hope I hepled

1

First of all, there is no need to write into an absolutely dead thread ..
Second, if you can't even think of a loop that can do 1 to 5, you might really want to consider starting from the basics ...
Third .. well here's a loop in 2 versions ..first for and then while loops

for(int i = 0; i<5;i++){
    System.out.println(i);
}

or ...

int i = 0;
while(i<5){
    System.out.println(i);
    i++; // means i = i + 1
}
Votes + Comments
or the simpler version: System.out.println("1,2,3,4,5"); :)
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.