Problem with my code, help would be appreciated.
so here is the code fragment
private int getChoice(int lower, int upper) {
System.out.println("--------------------------------------------------------------");
System.out.println("Please enter your choice: ");
String userSelection = Keyboard.readInput();
Integer.parseInt(userSelection);
if (userSelection >= lower && userSelection <= upper){
return userSelection;
}else{
displayMainMenu();
}
the problem is ">="
where it says "bad operand types for binary operator '>=' "
first type: java.lang.string
second type: int
Integer.parseInt(userSelection); this line is supossed to turn the string to an int and now im super confused.
thanks in advance :)
Re: Problem with my code, help would be appreciated.
Integer.parseInt(userSelection) returns an integer. you must create an int variable and store it, or simply paste the same code where userSelection is in the if statement
Re: Problem with my code, help would be appreciated.
The binary operator: >= can not be used to compare a String to an int. One solution would be to convert the String to an int and then compare two int values.
Re: Problem with my code, help would be appreciated.
yeah thank you guys i got it to work :)