First off, I am a noob so my experience in writing code is only about a month long.
I wrote a little program that asks the user to pick a number between 1 and 10.
I've also coded a random number generator to pick a number between 1 and 10.
My question is, how do I write the code so that if the user guesses a number and it happens
to equal the random number, a message is displayed.
Here is what I got so far:
import java.util.Random;
import java.util.Scanner;
public class practice {
public static void main(String args[]){
//Calling random object and calling it
//thingy
Random thingy = new Random();
//Calling a Scanner and calling it guess
Scanner guess = new Scanner(System.in);
int number;
int yourguess;
System.out.println("Enter a number between 1 and 10, if you guess the correct number there will be a surprise message: ");
yourguess = guess.nextInt();
for (int counter=1; counter<=10; counter++){
number = 1+thingy.nextInt(10);
if (number = yourguess)
System.out.println("Holy cow, you guessed the correct number!");
else
System.out.println("You guessed the wrong number");
}
}
}
The problem is I get and error stating: Type mismatch: cannot convert from int to boolean
I understand what it's saying but how do I fix it?
Thanks,
Shane

New Topic/Question
Reply




MultiQuote



|