Unresolved compilation problems:
import java.util.Random;
import java.util.*;
public class rendom_number {
/**
Suppose you want to develop a program to let a first-grader practice addition. The program
randomly generates two single-digit integers, number1 and number2, and displays to the student
a question such as “What is 7+9 ”, as shown in the sample run. After the student types
the answer, the program displays a message to indicate whether it is true or false.
*/
public static void main(String[] args) {
do{
Random rand = new Random();
int num1=rand.nextInt(10);
int num2=rand.nextInt(10);
int input,sum;
Scanner in=new Scanner(System.in);
System.out.print("What is "+num1 +"+"+num2 +"=");
input=in.nextInt();
sum=num1+num2;
if(sum==input)
{
System.out.print("True");
}
else
{
System.out.print("False");
}
}while(sum != input);
}
}
What is that error plz someone explane
....in last line while loop "sum" and "input" not excess ...error is "sum cannot be resolved to a variable
input cannot be resolved to a variable"...
Re: Unresolved compilation problems:
Don't declare the variables sum and input in the body of your do ... while loop, but declare them above the 'do' part of your loop.
kind regards,
Jos
Re: Unresolved compilation problems: