Advertisement
project_number_03

CountLetterCodes

Jan 25th, 2019
209
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.98 KB | None | 0 0
  1. public class Main {
  2.  
  3.     public static void main(String[] args) {
  4.         String str = "программисты крутые ребята";
  5.         int[] summWords = getSumm(str);
  6.         int summ = 0;
  7.         System.out.print("По словам: ");
  8.         for(int i = 0; i < summWords.length; i++){
  9.             System.out.print(summWords[i] + " ");
  10.             summ += summWords[i];
  11.         }
  12.         System.out.print("\nПо предложению: " + summ);
  13.     }
  14.  
  15.     public static int getLetterCode(char chr){
  16.         if((int)chr >= 1072 && (int)chr <= 1103) return (int)chr - 1071;
  17.         return 0;
  18.     }
  19.  
  20.     public static int[] getSumm(String str){
  21.         String[] split = str.toLowerCase().split(" ");
  22.         int[] summ = new int[split.length];
  23.         for(int i = 0; i < split.length; i++){
  24.             for(int j = 0; j < split[i].length(); j++){
  25.                 summ[i] += getLetterCode(split[i].charAt(j));
  26.             }
  27.         }
  28.         return summ;
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement