Advertisement
CR7CR7

CharSum

Sep 23rd, 2022
978
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.47 KB | None | 0 0
  1. import java.util.Scanner;  
  2. public class SumOfDigitsExample1  
  3. {  
  4. public static void main(String args[])  
  5. {  
  6.  
  7. Scanner sc = new Scanner(System.in);  
  8. //System.out.print("Enter the number: ");
  9. int countSymbols =Integer.parseInt(sc.nextLine());
  10.  
  11. int sum =0;  
  12. for(int symbol=1;symbol<=countSymbols;symbol++)  {
  13.   char value =sc.nextLine().charAt(0);
  14.   sum+=(int)value;
  15.  
  16.  
  17. }
  18.  
  19.  
  20.  //prints the result  
  21. System.out.printf("The sum equals: %d",sum);  
  22. }  
  23. }  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement