Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.util.Scanner;
- public class CharacterMultiplier {
- public static void main(String[] args) {
- Scanner sc = new Scanner(System.in);
- String input = sc.nextLine();
- String first = input.substring(0, input.indexOf(" ")).trim();
- String second = input.substring(input.indexOf(" ") + 1).trim();
- int sum = calcSumOfChars(first, second);
- System.out.println(sum);
- }
- private static int calcSumOfChars(String first, String second) {
- int sum = 0;
- for (int i = 0; i < first.length() && i < second.length(); i++) {
- sum += first.charAt(i) * second.charAt(i);
- }
- if (first.length() > second.length()) {
- for (int i = second.length(); i < first.length(); i++) {
- sum += first.charAt(i);
- }
- } else {
- for (int i = first.length(); i < second.length(); i++) {
- sum += second.charAt(i);
- }
- }
- return sum;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement