I want to read the identifier, name and account from the console for another use. However, these three variables are inside the scope of the try-catch block. I wonder if there is a way to get these three values from try-catch. ( If I do not want to put the three variables separately in the three pairs of the try-catch block ) Thanks for the time.
Here is my sample code:
StuManage sm = new StuManage();
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Please enter the student ID: ");
try {
String Id = br.readLine();
String name = br.readLine();
float score =Float.parseFloat(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
source
share