Why does this simple counter double in a simple Java application?
public class MyTestClass {
public static void main(String[] args) throws Exception {
char c;
InputStreamReader reader = (new InputStreamReader(System.in));
System.out.println("Enter chars:");
OutputStream outputStream = new BufferedOutputStream(System.out);
int counter = 0;
do {
counter++;
c = (char) reader.read();
outputStream.write(c);
outputStream.flush();
System.out.println(counter);
} while (c != 'q');
}
}
I'm trying to just type in a character and then hit enter.
What will I see:
Enter chars:
a
a1
2
b
b3
4
+3
source to share