Reputation: 826
So here's the problem: I'm trying to make my code simple. I'm reading from a file that has multiple data items in one line, so I'd like to split them up and put them in the corresponding array. However, the IDE keeps telling me it cannot find the symbol. I've already tried importing the string class (right word?) and moving my element array to within the WHILE loop.
What am I doing wrong?
import java.util.Scanner;
import java.io.File;
import java.io.IOException;
import java.lang.String;
public class Hurricanes2
{
public static void main(String [] args) throws IOException
{
int counter = 0;
String [] token = new String[64];
String [] hurrcaneYear = new String[64];
String [] hurrcaneName = new String[64];
int [] hurricaneCategory = new int[64];
double [] hurrcanePressure = new double[64];
double tempKnots;
double knotsToMph;
double [] hurricaneWindSpeeds = new double[64];
double categoryAverage;
double pressureAverage;
double speedAverage;
String headerData = " Hurricanes 1980 - 2006\n\n Year Hurricane Category Pressure(MB) Wind Speed (MPH)\n========================================================================";
Scanner in = new Scanner(System.in);
Scanner inFile = new Scanner(new File("hurcData2.txt"));
System.out.print(headerData);
/**---Use for-each (line:token)
* Parse for year - > year array
* parse for name - > name array
* parse for knots - > tempKnots
* knotsToMph = tempKnots * 1.15078
* hurricaneWindSpeed[counter] = knotsToMph
* enter if-else to calculate category (hurricaneCategory [] = 1,2,3,4, or 5):
* 74-95 cat1
* 96-110 cat2
* 111 - 129 cat3
* 130-156 cat4
* 157 or higher cat 5
*
*
*/
while(inFile.hasNext())
{
token[counter] = in.nextLine();
String tokenElements[] = token.split(" ");
counter++;
}
for(String line:token)
{
}
}
}
Upvotes: 1
Views: 13001
Reputation: 93842
You can only apply the split
method on a String
object, not on an array
of String
objects.
I think you want to do :
token[counter] = in.nextLine();
String tokenElements[] = token[counter].split(" ");
// this form is discouraged
float anArrayOfFloats[];
Convention discourages this form; the brackets identify the array type and should appear with the type designation.
Even if it's compile, I'd suggest to declare your array as String [] tokenElements
Upvotes: 7