+ 5
Can you tell what is wrong with my code?
There is something wrong with my code. There are errors . Please help me find them. https://code.sololearn.com/cDpjYbfzznpT/?ref=app
13 odpowiedzi
+ 12
// import Scanner
import java.util.Scanner;
import java.util.Random;
and replace b in if statement with a!
+ 11
Please, show us yours code so we can help you!
+ 8
Mind To Machine 🤖😎 yes your right if the input its not greater or less then it will go to else 😉👍
+ 6
Queen Arthur ,Brunnhilde [BUSY] ,Mind To Machine 🤖😎 ,Danijel Ivanović it was another lag. Here is the code. I am very sorry.
+ 5
Danijel Ivanović I'll see tomorrow and see if I understand. Okay.
+ 5
Mind To Machine 🤖😎 problem fixed! Thanks!
+ 4
Brunnhilde [BUSY] what comma? You mean this ; ?
+ 4
in the first if statement,where did you defined variable b?
+ 4
Danijel Ivanović I changed it but it still won't work....
+ 4
Danijel Ivanović dunno what you mean....
+ 3
can you post the code please?
+ 3
/*
This will NOT work on the SoloLearn java IDE because of the infinite loop or only if your first guest is correct, so run on you own IDE
*/
import java.util.Scanner;
import java.util.Random;
public class Program
{
// edited by MindToMachine 7:15 Sat, November 10 2018 AST
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
Random r = new Random();
int a = r.nextInt(10)+1;
while (true) {
//Guess and enter a number between 1 to 10
System.out.println("Guess A Number Between 1 And 10");
int c = sc.nextInt();
if(a>c) {
System.out.print("The number is too small");
}
if (a<c){
System.out.println("The number is too big");
}
else {
System.out.println("Congrats! Your guess is correct! Run this code again if you want to guess another number!");
break;
}
}
}
}
+ 2
D_Stark i think the else statement will handle the correct guest😎