desislava_topuzakova

04. Sum of Chars

May 29th, 2021
1,244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.60 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class elevator {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         //за всеки символ -> прочитаме -> сумираме int стойността
  7.         int n = Integer.parseInt(scanner.nextLine()); //брой на символите
  8.         int sum = 0; //сума от ascii codes
  9.         for (int count = 1; count <= n; count++) {
  10.             char symbol = scanner.nextLine().charAt(0);
  11.             sum += (int)symbol;
  12.         }
  13.  
  14.         System.out.println("The sum equals: " + sum);
  15.  
  16.     }
  17. }
Advertisement
Add Comment
Please, Sign In to add comment