import java.util.Scanner; import java.util.regex.Pattern; import java.util.regex.Matcher; public class FourIsLargerThanSeven { static Scanner scanner = new Scanner(System.in); public static void main(String[] args){ char[] A = Input(1 , 2000000000); char[] B = Input(1 , 2000000000); int Answer ; if(A.length > B.length){ String Character = String.valueOf(A); Answer = Integer.valueOf(Character); }else if(A.length < B.length){ String Character = String.valueOf(B); Answer = Integer.valueOf(Character); }else{ Answer = Comparison(A,B); } System.out.println(Answer); } public static char[] Input(int Min , int Max){ String TheNumber = scanner.next(); try{ Pattern pattern = Pattern.compile("[^0-9]"); Matcher matcher = pattern.matcher(TheNumber); if(matcher.find()){ System.out.println("数字を入力してください"); System.exit(0); } if(Integer.valueOf(TheNumber) < Min || Integer.valueOf(TheNumber) > Max){ System.out.println(Min + "以上" + Max + "以下で入力してください"); System.exit(0); } }catch(Exception E){ System.out.println("想定外のエラーです"); System.exit(0); } char[] Number = TheNumber.toCharArray(); return Number; } public static int Comparison(char[] A , char[] B){ int Answer = 0; for(int i = 0 ; i < A.length ; i++){ if(A[i] > B[i]){ if(A[i] == '7' && B[i] == '4'){ Answer = Integer.valueOf(String.valueOf(B)); return Answer; } }else if(A[i] < B[i]){ if(A[i] == '4' && B[i] == '7'){ Answer = Integer.valueOf(String.valueOf(A)); return Answer; } } } int NumberA = Integer.valueOf(String.valueOf(A)); int NumberB = Integer.valueOf(String.valueOf(B)); if(NumberA > NumberB){ Answer = NumberA; }else{ Answer = NumberB; } return Answer; } }