convertmenu.java
来自「Java 入门书的源码」· Java 代码 · 共 40 行
JAVA
40 行
//Copyright (c) 1998, Arthur Gittleman
//This example is provided WITHOUT ANY WARRANTY either expressed or implied.
/* Tests the structure of the program
* to convert length using a menu to
* get the user's choice. Uses stubs
* for the actual conversion methods.
*/
import iopack.Io;
public class ConvertMenu {
public static void MetricToEnglish() {
System.out.println("Converting from meters to yds,ft,in");
}
public static void EnglishToMetric() {
System.out.println("Converting from yds,ft,in to meters");
}
public static void main(String [] args) {
int choice;
do {
System.out.println();
System.out.println("Choose from the following list");
System.out.println("1. Convert from meters to yds,ft,in");
System.out.println("2. Convert from yds,ft,in to meters");
System.out.println("3. Quit");
choice = Io.readInt("Enter your choice, 1, 2 or 3");
switch (choice) {
case 1:
MetricToEnglish();
break;
case 2:
EnglishToMetric();
break;
case 3: System.out.println("Bye, Have a nice day");
}
} while (choice != 3);
Io.readString("Press any key to exit"); // Added for IDE use
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?