我想做,Java选择一个选项,执行那段功能。程序一部分如图所示,在输入1之后都只有一个?出来
2个回答
展开全部
没明白你为什么要用TextIO这个类 不是有System.out.println了么 TextIO 我默认库里面没有找到,我写了一个 你可以参考下
import java.util.Scanner;
public class MenuTest {
.//用途:打印menu菜单
public static void menu() {
System.out.println("Please input a number:");
System.out.println("0 - to quit");
System.out.println("1 - to get a price");
System.out.println("2 - to put money for your banlance");
System.out.println("3 - to conversation time");
System.out.println("4 to get statistics");
}
public static void main(String[] args) {
menu();
//利用Scanner类接收用户输入的数字
Scanner input = new Scanner(System.in);
int choice = input.nextInt();
while (choice != 0) {
switch (choice) {
case 0:
System.exit(0);
break;
case 1:
System.out.println("doSomething");
choice = input.nextInt();//重新给choice赋值 否则死循环
break;
}
}
}
}
import java.util.Scanner;
public class MenuTest {
.//用途:打印menu菜单
public static void menu() {
System.out.println("Please input a number:");
System.out.println("0 - to quit");
System.out.println("1 - to get a price");
System.out.println("2 - to put money for your banlance");
System.out.println("3 - to conversation time");
System.out.println("4 to get statistics");
}
public static void main(String[] args) {
menu();
//利用Scanner类接收用户输入的数字
Scanner input = new Scanner(System.in);
int choice = input.nextInt();
while (choice != 0) {
switch (choice) {
case 0:
System.exit(0);
break;
case 1:
System.out.println("doSomething");
choice = input.nextInt();//重新给choice赋值 否则死循环
break;
}
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询