无脑打印。
import java.util.Scanner; public class Main { 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; } } public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println(compare(sc.nextInt(), sc.nextInt())); System.out.println(compare(sc.next().charAt(0), sc.next().charAt(0))); // 这里注意,Scanner 对象没有 nextChar() 方法,next() 读进来的是字符串,可以通过 charAt(0) 取第一个字符。 System.out.println(compare(sc.next(), sc.next())); sc.close(); } }
0.0分
0 人评分
The 3n + 1 problem (C语言代码)浏览:1338 |
C二级辅导-进制转换 (C语言代码)浏览:811 |
C二级辅导-等差数列 (C语言代码)浏览:761 |
C语言程序设计教程(第三版)课后习题10.3 (C语言代码)浏览:682 |
程序员的表白 (C语言代码)浏览:1457 |
C语言程序设计教程(第三版)课后习题7.2 (Java代码)浏览:681 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:520 |
C语言程序设计教程(第三版)课后习题11.1 (C语言代码)浏览:623 |
C语言训练-计算一个整数N的阶乘 (C语言代码)浏览:928 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:548 |