I have to read options of menu from console and the options can be integer or string. my question is if there is another way to check of the input is string or int
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Read {
public Object read(){
String option = null;
BufferedReader buffer = new BufferedReader(new InputStreamReader(System.in));
try {
option = buffer.readLine();
if(isInt(option)){
return Integer.parseInt(option);
} else if(isString(option)){
return option;
}
} catch (IOException e) {
System.out.println("IOException " +e.getMessage());
}
return null;
}
private boolean isString(String input){
int choice = Integer.parseInt(input);
if(choice >= 0){
return false;
}
return true;
}
private boolean isInt(String input){
int choice = Integer.parseInt(input);
if(choice >= 0){
return true;
}
return false;
}
}