Sum numbers from file [on hold]
Sum numbers from file [on hold]
The text file looks like this:
1,2,3,4,5
The code looks like this:
import java.util.*;
import java.io.*;
public class tester
public static void main(String args)
Scanner sc = new Scanner(new File("Numbers.txt"));
sc.useDelimiter(",");
int sum = 0;
while (sc.hasNext())
int n = sc.nextInt();
sum += n;
System.out.println(sum);
How can I improve its perfomance?
Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
Please stick to Java naming conventions. Class names always in
PascalCase
. So Tester
, not tester
. Thanks.– Zabuza
2 days ago
PascalCase
Tester
tester
@Zabuza: This question shouldn't go to Code Review. Please don't suggest it as a potential candidate until you've thoroughly familiarized yourself with its migration policies.
– Makoto
2 days ago
What's wrong with that code? Why do you think it's slow? Did you measure it? If so, how? Also, this question might be more appropriate on Code Review instead of StackOverflow. In the current state your question is unclear.
– Zabuza
2 days ago