I have the following file
This file will t3est the pr0gram t0 ch3ck if the f1le contains 0.04 and 1000
letters .4
also this file makes no sense -88 at all. Test you program
7this 9.....
I want to read all the integer and double values. But my program is only able to read 1000-88
. Is there a better delimiter that could be used?
Here is my code
public static double sumNumbers(String filename) {
Scanner s = null;
try {
s = new Scanner(new File(filename)).useDelimiter("\\s+");
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
while (s.hasNext()) {
if (s.hasNextInt()) {
System.out.print(s.nextInt());
} else {
s.next();
}
}
return 0;
}