RGAlex

O2. Character Multiplier / Text Processing - Exercise

Mar 12th, 2021
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.72 KB | None | 0 0
  1. package TextPlocessing.Exercise;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class O2CharacterMultiplier {
  6.     public static void main(String[] args) {
  7.         Scanner scanner = new Scanner(System.in);
  8.         String[] input = scanner.nextLine().split(" ");
  9.         int sum = 0;
  10.         String first = input[0], second = input[1];
  11.         if (first.length() > second.length()) {
  12.             first = input[1];
  13.             second = input[0];
  14.         }
  15.         for (int i = 0; i < first.length(); i++) {
  16.             sum += first.charAt(i) * second.charAt(i);
  17.         }
  18.         for (int a = first.length(); a < second.length(); a++) {
  19.             sum += second.charAt(a);
  20.         }
  21.         System.out.println(sum);
  22.     }
  23. }
  24.  
Advertisement
Add Comment
Please, Sign In to add comment