Advertisement
desislava_topuzakova

04. Sum of Chars

Jan 23rd, 2021
721
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.53 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class SumOfChars_04 {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.         int countSymbols = Integer.parseInt(scanner.nextLine());
  7.  
  8.         //1. прочитаме символ
  9.         //2. сумираме
  10.         int sum = 0;
  11.         for (int i = 1; i <= countSymbols ; i++) {
  12.             char symbol = scanner.nextLine().charAt(0);
  13.             sum += (int)symbol;
  14.  
  15.         }
  16.  
  17.         System.out.println("The sum equals: " + sum);
  18.     }
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement