Contents of file patch.txt:
1
2
3
4
5
My code:
int sum = 0;
Scanner s = new Scanner (new File("patch.txt"));
while (s.hasNextLine()){
String [] str = s.nextLine().split("/r");
for (int i=0; i<str.length; i++){
sum+=Integer.parseInt(str[i]);
}
System.out.print(sum); //the result is 15
}
s.close();
}
}
When I sum the data must be 15, but why do I always get an error?