How do i split a text file ?
say a text file had lines like this :
Jekyll 23.3 33.3 43.2
khaki 32.5 54.3 43.2
.....
so far for my code i have this :
while(scan.hasNext())
{
String line = scan.nextLine();
String[] words = .split(" ");
for(int i = 1; i < words.length - 1; i++)
System.out.println(words[i]);
edit
now this is printed, my goal is to add all the numbers togeather and then create an average, Im stuck on what needs to be done here
edit entire code:
import java.util.Scanner;
import java.io.File;
import java.io.IOException;
import java.text.DecimalFormat;
public class TemperaturesWeek2
{
public static void main( String [] args ) throws IOException
{
int count=0;
double averageTemp;
int averageAbove;
double highestAverage;
File inputFile = new File (
"C:/Users/Phillip/Documents/Temp/temperatures.txt .txt");
Scanner scan = new Scanner(inputFile);
while(scan.hasNext()) {
String words = scan.next();
double num1 = scan.nextDouble();
double num2 = scan.nextDouble();
double num3 = scan.nextDouble();
double num4 = scan.nextDouble();
double num5 = scan.nextDouble();
double num6 = scan.nextDouble();
double num7 = scan.nextDouble();
double average = (num1 + num2 + num3+ num4+ num5+ num6+ num7) / 7;
System.out.println(words);
System.out.println("average is : " + average);
}
}
}
}