Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Just a beginner - Need help with a simple program!!

Status
Not open for further replies.

SurvivorTiger

Programmer
Jul 9, 2002
265
US
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
 
Hi,

I've answered your post in thread thread137-873572 .

Couple of things ...

Please don't cross-post in other forums in the future.
Also, this forum is for J2EE, the J2SE forum is forum269 .



--------------------------------------------------
Free Database Connection Pooling Software
 
if(MyChar == 'q') x++;
should be
if(MyChar == 'q'; x++)
 
Thanks to paul84 for his reply.

sedj: Even though you used "please", it would be nicer if you would assume SurvivorTiger was a newbie. Next time, explain to him/her what "cross-posting" is before admonishing him for a simple mistake.

- GW White

** Gerry White
** ** Are we having fun yet?
 
GerryWhite : Sorry, don't agree - if you look at "SurvivorTiger"'s user profile they have been a member since July 2002, and have posted 85 threads, and as such is not a newbie, and so should not be crossposting.

--------------------------------------------------
Free Database Connection Pooling Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top