I'm a beginner programmer, I have been writing code for about three weeks now. I want to make a simple program that asks for user input temperature and tells whether or not the user has fever (temperature higher than 39). I also want to validate the user input, meaning that if the user types "poop" or "!@·R%·%" (symbol gibberish), the program will output the phrase "invalid input". I'm trying to use the try/catch statements, this is my code:
package feverPack;
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException{
try{
InputStreamReader inStream = new InputStreamReader(System.in);
BufferedReader stdIn = new BufferedReader(inStream);
System.out.println("please input patient temperature in numbers");
String numone =stdIn.readLine();}
catch (IOException e) {
System.out.println("invalid input");
}
catch (NumberFormatException e){
System.out.println("invalid input");
}
int temp = Integer.parseInt(numone) ;
System.out.println("Your temperature is " + temp + "ºC");
if (temp > 39) {
System.out.println("You have fever! Go see a doctor!");
}
else{
System.out.println("Don't worry, your temperature is normal");
}
}
}
There is an error in line 22 (when i transform numone into a temp) saying "numone cannot be resolved to a variable", as I am a beginner I don't really know what to do, please help.