Pete1

Untitled

Mar 22nd, 2016
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.File;
  3. import java.io.FileReader;
  4. import java.io.IOException;
  5.  
  6. /**
  7. * Created by petar on 22.3.2016 г..
  8. */
  9. public class Problem1SumLines {
  10. public static final String filePath = "C:\\Program Files (x86)\\lines.txt";
  11.  
  12.  
  13. public static void main(String[] args) throws IOException {
  14.  
  15. File file = new File(filePath);
  16. BufferedReader reader = new BufferedReader(new FileReader(file));
  17. String line = reader.readLine();
  18.  
  19.  
  20. while (line != null) {
  21. int sumOfChars = 0;
  22.  
  23. String[] chars = line.split("");
  24.  
  25. for (int i = 0; i < chars.length; i++) {
  26. String currentChar = chars[i];
  27.  
  28. for (int j = 0; j < currentChar.length(); j++) {
  29. sumOfChars += currentChar.charAt(j);
  30.  
  31. }
  32.  
  33. }
  34.  
  35.  
  36. System.out.println(sumOfChars);
  37. }
  38.  
  39.  
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment