Go Back   Flash Flash Revolution > General Discussion > Technology
Register FAQ Community Calendar Today's Posts Search

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Old 02-28-2012, 03:49 PM   #1
Crashfan3
FFR Player
 
Crashfan3's Avatar
 
Join Date: Nov 2006
Location: Jefferson, Ore.
Age: 34
Posts: 2,937
Send a message via AIM to Crashfan3 Send a message via Skype™ to Crashfan3
Default [JAVA] Variable might not have been initialized?

Hi,

I'm trying to write a program that reads a list of golf scores from a text file, and then stores each golfer's score to memory.
The scores are in the text file like this:
3 4 3 2 5 (18 lines like this, where the first number is par, the others are each golfer's score)
My program reads each hole just fine but I can't figure out how to properly store each golfer's score and add them up to get a final score so that I can determine who wins.

My loop looks like this:
Code:
// Print each golfer's score individiually
while (holeScan.hasNext())
{
	int par;
	int g1score, g2score, g3score, g4score;
	System.out.println("PAR    : " + holeScan.next());
	par = Integer.parseInt(holeScan.next());
	System.out.println("Golfer1: " + holeScan.next());
	g1score = g1score + Integer.parseInt(holeScan.next());
	System.out.println("Golfer2: " + holeScan.next());
	g2score = g2score + Integer.parseInt(holeScan.next());
	System.out.println("Golfer3: " + holeScan.next());
	g3score = g3score + Integer.parseInt(holeScan.next());
	System.out.println("Golfer4: " + holeScan.next());
	g4score = g4score + Integer.parseInt(holeScan.next());
}
When I compile, I'm being told that each of the variables above "might not have been initialized." When I set them all equal to zero, I get a short set of incorrect results followed by an exception.


I'm not begging for someone to write my code for me, but I can't get my head around this little piece so I thought I'd come here for help since this is due tomorrow morning.

If you need the rest of my code, just ask.
Thanks!!
__________________
Crashfan3 is offline   Reply With Quote
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is On
HTML code is Off

Forum Jump



All times are GMT -5. The time now is 07:10 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Copyright FlashFlashRevolution