public class SubtractFile {
public static void main(String[] a) throws IOException {
edmw("\\thesubtraction.txt");
}
static void edmw(String filename) throws IOException {
Reader r = new BufferedReader(new FileReader(filename));
StreamTokenizer stok = new StreamTokenizer(r);
stok.parseNumbers();
double finalresult = 0;
int count = 0;
stok.nextToken();
while (stok.ttype != StreamTokenizer.TT_EOF) {
if (stok.ttype == StreamTokenizer.TT_NUMBER) {
if (count == 0) {
finalresult = stok.nval;
} else {
finalresult -= stok.nval;
}
count++;
}
else {
System.out.println("Nonnumber: " + stok.sval);
stok.nextToken();
}
System.out.println("The result of subtraction is " + finalresult);
}
}
}
What is wrong with these code ? I am trying to perform an action whereby the 1st integer minus away the 2nd integer. Followed by the 2nd integer minus away the 3rd integer in the file.


Sign In
Create Account


Back to top









