Advertisement
Valleri

C# Basics Exam 25 July 2014 Morning - 02. Letters, Symbols,

Aug 1st, 2014
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.92 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3.  
  4. public class LettersSymbolsNumbers {
  5.  
  6.    
  7.     public static void main(String[] args) {
  8.         Scanner input = new Scanner(System.in);
  9.        
  10.         int sumLetters = 0;
  11.         int sumNumbers = 0;
  12.         int sumSymbols = 0;
  13.        
  14.         int n = input.nextInt();
  15.         input.nextLine();
  16.         for (int i = 0; i < n; i++) {
  17.             String currentString = input.nextLine();
  18.            
  19.             for (int j = 0; j < currentString.length(); j++) {
  20.                 char currChar = currentString.charAt(j);
  21.                
  22.                 if (Character.isLetter(currChar)) {
  23.                     currChar = Character.toUpperCase(currChar);
  24.                     sumLetters += (((int) currChar - 64) * 10);
  25.                 }
  26.                 else if (Character.isDigit(currChar)) {
  27.                     sumNumbers += Character.getNumericValue(currChar) * 20;
  28.                 }
  29.                 else {
  30.                     if (!Character.isWhitespace(currChar)) {
  31.                         sumSymbols += 200;
  32.                     }          
  33.                 }
  34.             }
  35.         }
  36.        
  37.         System.out.printf("%d\n%d\n%d", sumLetters, sumNumbers, sumSymbols);
  38.  
  39.     }
  40.  
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement