Advertisement
desislava_topuzakova

04. Sum of Chars

May 27th, 2022
874
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.56 KB | None | 0 0
  1. package DataTypesVariables;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class SumOfChars_04 {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         int n = Integer.parseInt(scanner.nextLine()); //брой символи
  9.         int sum = 0; //сума от аски кодове
  10.         for (int i = 0; i < n; i++) {
  11.             char symbol = scanner.nextLine().charAt(0);
  12.             int asciiCode = (int) symbol;
  13.             sum += asciiCode;
  14.         }
  15.  
  16.         System.out.printf("The sum equals: %d", sum);
  17.     }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement