Hey everyone. Slightly a beginner here but I'm doing Computer Science in high school. I use JCreator to write my codes and I just need a little help with the logic I need to use and some functions I would need to use.
The task:
First we made a code on inputting numbers using InputStreamReader and what the program had to do was create a multiplication table of numbers.
First it had to ask for which number you want to multiply by -- let's say 5
Then, it asked from which value you want to start multiplying -- let's say 2
Finally, it asked for the last number in which the program would stop multiplying -- let's say 10
basically it printed out
2*5=10
3*5=15
4*5=20
.
.
.
10*5=50
then it stopped.
What I need to do now is to create an if function which asks that once that is completed, if the user wants to continue running that program. The program will keep running unless the user gives a command for it to stop.
Also, my teacher recommended me to use methods and functions instead of doing everything in the public static void main.
here's the code
import java.io.*; public class ForLoop { public static void main(String[] args) throws IOException { InputStreamReader in=new InputStreamReader(System.in); BufferedReader strbuf=new BufferedReader(in); System.out.println("Enter table for: "); int number=Integer.parseInt(strbuf.readLine()); System.out.println("The number you have entered is: "+number); System.out.println("Enter first value: "); int first=Integer.parseInt(strbuf.readLine()); System.out.println("The first value you have entered is: "+first); System.out.println("Enter last value: "); int last=Integer.parseInt(strbuf.readLine()); System.out.println("The last value you have entered is: "+last); for(int initial=first;initial<=last;initial++) { System.out.println(initial + "X" + number + "=" + (initial * number)); } } }
any ideas?
Thanks!!