Advertisement
CR7CR7

checkUps

Jun 14th, 2023
804
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.91 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class CompareCharArrays {
  4.     public static void main(String[] args) {
  5.         Scanner scanner = new Scanner(System.in);
  6.  
  7.        
  8.         String firstArrayString = scanner.nextLine();
  9.  
  10.        
  11.         String secondArrayString = scanner.nextLine();
  12.  
  13.        
  14.         int firstArraySum = computeUnicodeSum(firstArrayString);
  15.  
  16.        
  17.         int secondArraySum = computeUnicodeSum(secondArrayString);
  18.  
  19.        
  20.         if (firstArraySum < secondArraySum) {
  21.             System.out.println("first");
  22.         } else if (firstArraySum > secondArraySum) {
  23.             System.out.println("second");
  24.         } else {
  25.             System.out.println("equal");
  26.         }
  27.     }
  28.  
  29.     private static int computeUnicodeSum(String arrayString) {
  30.         int sum = 0;
  31.         for (char c : arrayString.toCharArray()) {
  32.             sum += c;
  33.         }
  34.         return sum;
  35.     }
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement