SurvivorTiger
Programmer
Hey everyone,
I'm fairly new to Java and i'm trying to make this simple useless program (just for the sake of practice) but I can't figure out with it is that's wrong with my code...
class CharReader {
public static void main(String args[]) throws java.io.IOException {
char MyChar;
int x;
do {
MyChar = (char) System.in.read();
if(MyChar == 'q') x++;
} while(MyChar != '.');
System.out.println("You pressed q " + x + " times.");
}
}
This is the error i get:
"variable x might not have been initialized"
I get the error twice for the "if(MyChar..." and "System.out...." line
Can anyone help me with this please?
AIM: survivertiger
I'm fairly new to Java and i'm trying to make this simple useless program (just for the sake of practice) but I can't figure out with it is that's wrong with my code...
class CharReader {
public static void main(String args[]) throws java.io.IOException {
char MyChar;
int x;
do {
MyChar = (char) System.in.read();
if(MyChar == 'q') x++;
} while(MyChar != '.');
System.out.println("You pressed q " + x + " times.");
}
}
This is the error i get:
"variable x might not have been initialized"
I get the error twice for the "if(MyChar..." and "System.out...." line
Can anyone help me with this please?
AIM: survivertiger