Hello im trying to get my head around a program and not getting anywhere. I need to access a external txt file that contains football score in the format below.
leeds united : liverpool : 3 : 1
manchester united : arsenal : 1 : 5
I then need to display the values in the correct order like below;
leeds united 3 Liverpool 1
manchester united 1 arsenal 5
Im trying to get it so i have each value seperate and i know if its a string or a int. can anyone help my code is below.
import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.io.Reader; import java.io.StreamTokenizer; public class temp { public static void main(String[] a) throws IOException { sumfile("C:\\Documents and Settings\\Nicky\\My Documents\\write.txt"); } static void sumfile(String filename) throws IOException { Reader r = new BufferedReader(new FileReader(filename)); StreamTokenizer stok = new StreamTokenizer(r); stok.parseNumbers(); double sum = 0; stok.nextToken(); while (stok.ttype != StreamTokenizer.TT_EOF) { if (stok.ttype == StreamTokenizer.TT_NUMBER) sum += stok.nval; else System.out.println(stok.sval); stok.nextToken(); } System.out.println("The number of goals is " + sum); } }