write a program that generates twointegers under 100 and prompts the user to ent
ID: 3609037 • Letter: W
Question
write a program that generates twointegers under 100 and prompts the user to enter the addition ofthese two integers, the program then reports true if correct andfalse otherwisethis is my program.....it outputs a false no matter what answer iput in it even the correct answer. so it is wrong. please help mefix my code. i will rate lifesaver for working code.
import java.util.*;
public class twointegers
{
public static void main(String[] args)
{
Random generator = newRandom();
Scanner key = newScanner(System.in);
int int1,int2,sum;
int1 =generator.nextInt(100);
int2 =generator.nextInt(100);
System.out.println("Enter thesum of " +int1 + " and " +int2);
sum = key.nextInt();
System.out.println((int1==sum));
}
}
Explanation / Answer
I think you want your final line of code to be System.out.println((sum == int1+int2)); so it the input is compared to int1 + int2 instead of just int1
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.