SHARE
TWEET

Untitled

shniaga Mar 26th, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package TextAndRegexExercise;
  2.  
  3. import java.util.ArrayList;
  4. import java.util.List;
  5. import java.util.Scanner;
  6.  
  7. public class LettersChangeNumbers_14 {
  8.     public static void main(String[] args) {
  9.         Scanner scanner = new Scanner(System.in);
  10.  
  11.         String[] input = scanner.nextLine().split("\\s+");
  12.         double finalNumber = 0.0;
  13.         double currentNumber = 0.0;
  14.  
  15.         List<Character> lowercase = new ArrayList<>();
  16.         List<Character> uppercase = new ArrayList<>();
  17.  
  18.         lowercase.add('@');
  19.         uppercase.add('@');
  20.  
  21.         for (int i = 'A'; i <= 'Z'; i++) {
  22.             uppercase.add((char) i);
  23.         }
  24.         for (int i = 'a'; i <= 'z'; i++) {
  25.             lowercase.add((char) i);
  26.         }
  27.         for (int i = 0; i < input.length; i++) {
  28.             currentNumber = 0.0;
  29.             String currentWord = input[i];
  30.             char before = currentWord.charAt(0);
  31.             char after = currentWord.charAt(currentWord.length() - 1);
  32.             int number = Integer.parseInt(currentWord.substring(1, currentWord.length() - 1));
  33.             if (uppercase.contains(before)) {
  34.                 int beforeIndex = uppercase.indexOf(before);
  35.                 currentNumber = (double) number / beforeIndex;
  36.             }
  37.             if (lowercase.contains(before)) {
  38.                 int beforeIndex = lowercase.indexOf(before);
  39.                 currentNumber = number * beforeIndex;
  40.             }
  41.             if (uppercase.contains(after)) {
  42.                 int afterIndex = uppercase.indexOf(after);
  43.                 currentNumber -= afterIndex;
  44.             }
  45.             if (lowercase.contains(after)) {
  46.                 int afterIndex = lowercase.indexOf(after);
  47.                 currentNumber += afterIndex;
  48.             }
  49.  
  50.             finalNumber += currentNumber;
  51.         }
  52.         System.out.printf("%.2f",finalNumber);
  53.     }
  54. }
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
 
Top