3,和4的区别就是,大小写不区分,一个是只是长度相同,那么我们就可以在都不相等的情况下再来一个&&,将字母全变大写或者小写,再来判断
import java.util.Locale; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); String a=scanner.next(); String b =scanner.next(); a.toCharArray(); b.toCharArray(); if (a.length()==b.length()){ if (a.equals(b)){ System.out.println(2); }else if(!a.equals(b)&&a.toUpperCase(Locale.ROOT).equals(b.toUpperCase(Locale.ROOT))){ System.out.println(3); }else if (!a.equals(b)&&!a.toUpperCase(Locale.ROOT).equals(b.toUpperCase(Locale.ROOT))) System.out.println(4); }else System.out.println(1); } }