解题思路:
思路比较简单,写三个重载的函数就行了。
注意事项:
参考代码:
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 人评分
整除问题 (C语言代码)浏览:883 |
【出圈】 (C++代码)(典型的约瑟夫环——链表解决)浏览:1207 |
十->二进制转换 (C++代码)(零和负数需要特殊处理)浏览:1040 |
母牛的故事 (C语言代码)浏览:435 |
哥德巴赫曾猜测 (C语言代码)浏览:995 |
打水问题 (C语言代码)浏览:1070 |
C语言程序设计教程(第三版)课后习题5.5 (C语言代码)浏览:557 |
川哥的吩咐 (C语言代码)浏览:611 |
数列问题 (C语言代码)浏览:1020 |
小O的乘积 (C++代码)浏览:750 |