#Java beginner, elseif not initializing
7 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @thin talon! Please use
/closeor theClose Postbutton above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
package numberguessgame;
import java.io.File;
import java.util.Scanner;
public class GuessingGame {
public static void guessingNumber() {
System.out.println("Welcome to the Number Guessing Game!" );
boolean gameRunner = true;
if (gameRunner) {
Scanner myDifficulty = new Scanner(System.in);
System.out.println("Choose a difficulty: Easy or Hard");
String gameDifficulty = myDifficulty.nextLine();
gameDifficulty = gameDifficulty.toLowerCase(); // normalizing
System.out.println(gameDifficulty);
if (gameDifficulty == "easy") {
int guessesRemaining = 10;
System.out.println("Working");
}
else if(gameDifficulty == "hard") {
System.out.println("Working");
int guessesRemaining = 5;
Scanner myGuess = new Scanner(System.in);
System.out.println("Choose a number between 1-100: ");
int numGuess = myGuess.nextInt();
System.out.println(numGuess);
gameRunner = false;
}
}
}
public static void resultsCompare(){
System.out.println("Test");
}
public static void main(String[] args){
guessingNumber();
}
}
Looks like you're having some trouble comparing strings, check out this stackoverflow question for help.
thanks, @supple haven
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.