虽然我已经解决了我之前遇到的 split() 问题(感谢最后一个帮助我的人!)我还有另一个问题。这在此处列出的代码中很明显,但是我不知道它是什么。问题是它只将文件的最后一行打印到输出中,而在这个阶段,我希望它打印出所有行。我需要解决什么问题?谢谢!!
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[1000];
String [] tokenElements = new String[128];
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.hasNextLine())
{
token[counter] = inFile.nextLine();
tokenElements = token[counter].split(" ");
counter++;
}
int counter2 = 0;
for(String line:tokenElements)
{
System.out.println(tokenElements[counter2]);
counter2++;
}
}