Advertisement
Spocoman

05. Compare Char Arrays

Oct 24th, 2024
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.88 KB | None | 0 0
  1. import java.util.Scanner;
  2. import java.util.Arrays;
  3.  
  4. class Main {
  5.     public static void main(String[] args) {
  6.         Scanner scanner = new Scanner(System.in);
  7.         String[] arrOne = scanner.nextLine().split(" ");
  8.         String[] arrTwo = scanner.nextLine().split(" ");
  9.      
  10.         if (arrOne.length < arrTwo.length) {
  11.             System.out.printf("%s\n%s\n", String.join("", arrOne), String.join("", arrTwo));
  12.         } else if (arrTwo.length < arrOne.length) {
  13.             System.out.printf("%s\n%s\n", String.join("", arrTwo), String.join("", arrOne));
  14.         } else {
  15.             int result = Arrays.toString(arrOne).compareTo(Arrays.toString(arrTwo));
  16.             System.out.printf("%s\n%s\n",
  17.                     String.join("", result <= 0 ? arrOne : arrTwo),
  18.                     String.join("", result <= 0 ? arrTwo : arrOne)
  19.             );
  20.         }
  21.     }
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement