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.

Recommended Answers

All 5 Replies

so, if I input 5 it should count 5,10,15,20,25 or 1,2,3,4,5 ?

yes 5 10 15 20 and soo on

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,2,3,4,5
can you do it sir?

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
}
commented: or the simpler version: System.out.println("1,2,3,4,5"); :) +13
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.