题目
题目概述
*4.24(对三个城市排序)编写一个程序,提示用户输入三个城市名称,然后以升序进行显示
运行示例
Enter the first city: Chicago
Enter the second city: Los Aneles
Enter the third city: Atlanta
The three cities in alphabetical order are Atlanta Chicago Los Angeles
破题
- 接收用户输入,赋值予String
- 比较(s0.comparTo(s1)),返回值>0则s0大于s1,=0则s0=s1,<0则s0小
- 根据大小输出(升序)
代码
import java.util.Scanner;
public class Test4_24 {
public static void main(String[] args) {
// 接收输入
Scanner input