|
-
Nov 26th, 2002, 02:41 PM
#1
Thread Starter
New Member
how do i loop a answer ????
hi how do i loop my code below, so that when a wrong answer is entered it will loop back and keep asking the same question till it is answered right.
import java.io.*;
class School2
{
public static void main (String[]args) throws IOException
{
int answer;
int total;
int No1;
int No2;
No1 =1+(int) (Math.random()*10);
No2 =1+(int) (Math.random()*10);
total=No1*No2;
String line;
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
{
System.out.println("Mulitply "+ No1+" by "+ No2);
line = input.readLine();
answer = Integer.parseInt(line);
if (answer == total)
System.out.println("Well Done the answer was "+" "+total);
else
if (answer != total)
System.out.println("Sorry try again");
}
}
}
thanks if you can help
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|