|
-
April 14th, 2010, 03:49 PM
#1
Variable Wont increment in while loop
Howdy, very new to java programming. I am reading in a text file from my computer and attempting to store it in an array of strings, one word per string. However, they all appear to be in the first string of the array. wordCount++ wont increment so I am able to store the strings in different spots in the array.
public void processLine(String aLine){
int wordCount = 0;
String[] wordList = new String [100];
Scanner scanner = new Scanner(aLine);
while( scanner.hasNext()){
String name = scanner.next();
wordCount++;
System.out.println("wordCount is " + wordCount);
wordList[wordCount] = name;
System.out.println("Value is " + wordList[wordCount]);
}
Any ideas?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|