Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.File;
- import java.io.FileReader;
- import java.io.IOException;
- /**
- * Created by petar on 22.3.2016 г..
- */
- public class Problem1SumLines {
- public static final String filePath = "C:\\Program Files (x86)\\lines.txt";
- public static void main(String[] args) throws IOException {
- File file = new File(filePath);
- BufferedReader reader = new BufferedReader(new FileReader(file));
- String line = reader.readLine();
- while (line != null) {
- int sumOfChars = 0;
- String[] chars = line.split("");
- for (int i = 0; i < chars.length; i++) {
- String currentChar = chars[i];
- for (int j = 0; j < currentChar.length(); j++) {
- sumOfChars += currentChar.charAt(j);
- }
- }
- System.out.println(sumOfChars);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment