package mygradeloops;
import java.io.IOException;
public class MyGradeLoops {
public static void main(String[] args) throws IOException {
char x = \'A\';
The read
method for System.in
(an InputStream
) only reads one byte of data from the input stream. Because you must hit "Enter" to send your input to the stream, you have two characters on the stream - the character you typed plus a newline.
The for
loop loops twice, and "double prints" Keep going!
and Please enter in one of your grades.
because each iteration reads one of the two characters on the stream.
It would be easier to wrap System.in
in a InputStreamReader
then a BufferedReader
or just initialize a Scanner
with System.in
. With a BufferedReader
you can just call readLine()
, and with a Scanner
you can call nextLine()
.
Also, it's unclear why you are looping from '0'
to '9'
with char
s. It would be clearer to use an int
for a
and loop from 0
until 9
.