SHARE
TWEET

CountLetterCodes

project_number_03 Jan 25th, 2019 95 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top