Advertisement
Guest User

Untitled

a guest
Feb 1st, 2015
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.27 KB | None | 0 0
  1. package asdfs;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.File;
  5. import java.io.FileNotFoundException;
  6. import java.io.FileReader;
  7. import java.io.IOException;
  8. import java.io.InputStreamReader;
  9. import java.io.PrintStream;
  10. import java.util.Scanner;
  11. import java.util.StringTokenizer;
  12.  
  13.  
  14. public class Sums
  15. {
  16. Scanner scan;
  17. PrintStream out;
  18. StringTokenizer st;
  19. String temp = "";
  20. public Sums() throws Exception
  21. {
  22.  
  23. scan = new Scanner( new File( "sums.in" ) );
  24. out = new PrintStream(new File("sums.out"));
  25.  
  26. }
  27. public void run() throws Exception
  28. {
  29.  
  30. while (scan.hasNext())
  31. {
  32. int sum = 0; //reset the sum
  33. String s = scan.nextLine();
  34.  
  35. int c = 0;
  36.  
  37. while (c < s.length())
  38. {
  39. temp = "";
  40. while (s.charAt( c )!= ',')
  41. {
  42. temp += s.charAt( c );
  43. c++;
  44. }
  45. sum += Integer.parseInt( temp );
  46. }
  47. out.println(sum);
  48. }
  49. }
  50.  
  51. public static void main( String[] args ) throws Exception
  52. {
  53. Sums s = new Sums();
  54. s.run();
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement