Can anyone please explain why the following code behaving strangely:
public class UserInputTest {
public static void main(String[] args) throws IOException {
int n=3;
char[] arr = new char[n];
for (int i=0; i<n; i++) {
System.out.println(i+1 + " character :");
arr[i] = ((char)System.in.read());
}
System.out.println("You Entered : ");
for (int i=0; i<n; i++) {
System.out.println(arr[i]);
}
}
}
OUTPUT:
1 character :
u
2 character :
3 character :
You Entered :
u
I was expecting it to block three times for a user to input values. Any comments ?
Thanks,
Mohit