RGAlex

O2. Ascii Sumator / Text Processing - More Exercise

Mar 15th, 2021
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.67 KB | None | 0 0
  1. package TextPlocessing.MoreExercises;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class O2AsciiSumator {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.  
  9.         char a = scanner.nextLine().charAt(0);
  10.         char b = scanner.nextLine().charAt(0);
  11.         String text = scanner.nextLine();
  12.  
  13.         int start = Math.min(a, b);
  14.         int end = Math.max(a, b);
  15.         int sum = 0;
  16.  
  17.         for (int i = 0; i < text.length(); i++) {
  18.             int charText = text.charAt(i);
  19.             if (charText > start && charText < end) {
  20.                 sum += charText;
  21.             }
  22.         }
  23.         System.out.println(sum);
  24.     }
  25. }
  26.  
Advertisement
Add Comment
Please, Sign In to add comment