Home > Back-end >  For help, how to realize the right to continue to exit the wrong answer?
For help, how to realize the right to continue to exit the wrong answer?

Time:10-12

If inscribe, want to let continue to get the correct answer to the next round of questions and answers, but the do... While statement couldn't identify the statements in the d variable, bosses help solve, thank you

Error message: Error message: the Exception in the thread "is the main" Java. Lang. Error: cannot resolve compilation problems:
D cannot be resolved to a variable
The at AdditionExercise. Main (AdditionExercise. Java: 19)
Code:
 

import java.util.Scanner;
import java.util.Random;
Public class AdditionExercise {
Public static void main (String [] args) {
The Random rand=new Random ();
Int a=rand. NextInt (100) + 1;
Int b=rand. NextInt (100) + 1;
Scanner sc=new Scanner(System.in);
Do {
System. The out. Println (" please enter the answer ");
System. The out. Println (a + "+ + +"="b");
Int c=sc. NextInt ();
Boolean d=(c==a + b);
If (d)
System. The out. Println (" the answer right ");
if (! D)
System. The out. Println (" wrong answer ");
sc.close();
} while (d);
}
}

CodePudding user response:

import java.util.Random;
import java.util.Scanner;
Public class DoTest {
Public static void main (String [] args) {
The Random rand=new Random ();
Int a=rand. NextInt (100) + 1;
Int b=rand. NextInt (100) + 1;
Scanner sc=new Scanner(System.in);

Boolean d=true;//the line
Do {
System. The out. Println (" please enter the answer ");
System. The out. Println (a + "+ + +"="b");
Int c=sc. NextInt ();
D=(c==a + b);
If (d)
System. The out. Println (" the answer right ");
if (! D)
System. The out. Println (" wrong answer ");
//sc. The close (); Such comments
} while (d);
}
}

CodePudding user response:

The
reference software on the second floor of pharaoh reply:
import Java. Util. Random;
import java.util.Scanner;
Public class DoTest {
Public static void main (String [] args) {
The Random rand=new Random ();
Int a=rand. NextInt (100) + 1;
Int b=rand. NextInt (100) + 1;
Scanner sc=new Scanner(System.in);

Boolean d=true;//the line
Do {
System. The out. Println (" please enter the answer ");
System. The out. Println (a + "+ + +"="b");
Int c=sc. NextInt ();
D=(c==a + b);
If (d)
System. The out. Println (" the answer right ");
if (! D)
System. The out. Println (" wrong answer ");
//sc. The close (); Such comments
} while (d);
}
}

I tried, why the topic is not random?
  • Related