解题思路:
思路比较简单,写三个重载的函数就行了。
注意事项:
参考代码:
import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int num1 = sc.nextInt(); int num2 = sc.nextInt(); char char1 = sc.next().charAt(0); //字符char的输入方法 char char2 = sc.next().charAt(0); String str1 = sc.next(); String str2 = sc.next(); System.out.println(Compare(num1, num2)); System.out.println(Compare(char1, char2)); System.out.println(Compare(str1, str2)); } public static int Compare(int a, int b) { if (a > b) { return a; } else { return b; } } public static int Compare(char a, char b) { return Math.abs((int) a - (int) b); } public static String Compare(String a, String b) { if (a.compareTo(b) > 0) { return a; } else { return b; } } }
0.0分
1 人评分