Hi
I am trying to tokenize a string from a file.
The file contains two lines that have different info. I need to tokenize the lines separately and compare the results of each line.
Now, I think my problem is identifying the separate lines to perform operations separately
/*
PROG: ride
*/
import java.io.*;
import java.util.*;
class ride {
public static void main (String [] args) throws IOException {
// Use BufferedReader rather than RandomAccessFile; it's much faster
BufferedReader f = new BufferedReader(new FileReader("ride.in"));
// input file name goes above
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("ride.out")));
// Use StringTokenizer vs. readLine/split -- lots faster
StringTokenizer st = new StringTokenizer(f.readLine());
// Get line, break into tokens
while (st.hasMoreTokens()){
int i1 = Integer.parseInt(st.nextToken()); // first value
int i2 = Integer.parseInt(st.nextToken()); // second value
int i3 = Integer.parseInt(st.nextToken()); // third value
int i4 = Integer.parseInt(st.nextToken()); // fourth value
int i5 = Integer.parseInt(st.nextToken()); // fifth value
int i6 = Integer.parseInt(st.nextToken()); // sixth value
int i7 = (i1 - 64)*(i2 - 64)*(i3 - 64)*(i4 - 64)*(i5 - 64)*(i6 - 64); // product values
int product = i7%47;
}
StringTokenizer st2 = new StringTokenizer(f.readLine());
// Get line, break into tokens
while (st2.hasMoreTokens()){
int i8 = Integer.parseInt(st.nextToken()); // first value
int i9 = Integer.parseInt(st.nextToken()); // second value
int i10 = Integer.parseInt(st.nextToken()); // third value
int i11 = Integer.parseInt(st.nextToken()); // fourth value
int i12 = Integer.parseInt(st.nextToken()); // fifth value
int i13 = Integer.parseInt(st.nextToken()); // sixth value
int i14 = (i8 - 64)*(i9 - 64)*(i10 - 64)*(i11 - 64)*(i12 - 64)*(i13 - 64); // product values
int product2 = i14%47;
}
if(product == product2) {
out.println("GO"); //Ready to go
}
else {
out.println("STAY"); //Next time guys!!
}
out.close(); // close the output file
System.exit(0); // don't omit this!
}
}
Any help would be highly appreciated.