I have the following lines of code for an assignment. What I don't understand is why, when I uncomment the first few println's before the user prompt in main, the input taken from the function readint seems to capture the first println and not what the user types in. If I leave them all commented, then readint works fine and returns the correct value.
import java.io.*;
class Interface{
static int readint(String str) {
int val = 0;
try {
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
System.out.print(str);
String theInput = br.readLine();
val = Integer.parseInt(theInput);
}
catch(Exception e) {
System.out.println("Error!" + e);
}
return val;
}
public static void main(String[] args){
//System.out.println("What account type do you want to make:");
//System.out.println("[1]MinBalance");
//System.out.println("[2]NickelnDime");
//System.out.println("[3]Gambler");
int xyz=readint("ENTER NUMBER: ");
System.out.println("NUM: "+xyz);
}
}
I am using JCreator Pro V4 with JDK 1.6.0.