4
29/10/2024 4:54 pm
Themenstarter
Write a program that reads a text file and prints on the console the sum of the ASCII symbols of each of its lines. Use BufferedReader in combination with FileReader.
1 Antwort
3
29/10/2024 4:55 pm
Here is my solution:
import java.io.*; public class Pr_01_SumLines { public static void main(String[] args) throws IOException { File lines = new File("resources/lines.txt"); BufferedReader reader = new BufferedReader(new FileReader(lines)); String line = reader.readLine(); while (line != null) { int symbolsTotalCount = 0; for (int i = 0; i < line.length(); i++) { symbolsTotalCount += line.charAt(i); } System.out.println(symbolsTotalCount); line = reader.readLine(); } reader.close(); } }