I’m new to java and having problems with getting input.
This is my code which seems to get the first input as required, but then skips the next two “read” function calls?
Any suggestions?
// open up standard input
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int battMax, battMin, numNodes=0;
System.out.print("Enter minimum battery level:");
try {
battMin = br.read();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
System.out.print("Enter maximum battery level:");
try {
battMax = br.read();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
System.out.print("Enter number of nodes required:");
try {
numNodes = br.read();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
br.read()reads a char. UseInteger.parseInt(br.readLine())which will read a whole line and convert it into anint.Also, initialize all your local variables: