Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class CharacterMultiplier {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- String[] input = scanner.nextLine().split(" +");
- String str1 = input[0].trim();
- String str2 = input[1].trim();
- int sum = 0;
- for (int index = 0; index < Math.max(str1.length(), str2.length()); index++) {
- if (index < str1.length() && index < str2.length()) {
- sum = sum + str1.charAt(index) * str2.charAt(index);
- } else if (index < str1.length()){
- sum += str1.charAt(index);
- } else {
- sum += str2.charAt(index);
- }
- }
- System.out.println(sum);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment