【发布时间】:2022-11-13 10:51:49
【问题描述】:
我是一名 IT 新生,如果用户输入 5,我们被要求创建一个程序来确定售出的物品总数,我看了几个 youtube 教程,但我不能理解它..任何帮助请。
该程序应显示 3 个选项,然后用户输入他/她的选项。之后,如果用户选择 5,则该程序应打印出已售出的商品数量。
import java.util.Scanner;
public class Machine{
public static void main(String[] args) {
int choice;
Scanner scan = new Scanner(System.in);
do {
System.out.println("[1] Get Gum");
System.out.println("[2] Get Chocolate");
System.out.println("[3] Get Popcorn");
System.out.println("[4] Get Juice");
System.out.println("[5] Display total sold items so far");
System.out.println("[6] Quit");
System.out.println("Your choice: ");
choice = scan.nextInt();
if (choice == 1 ) {
System.out.println("Here is your Gum ");
}
else if (choice == 2 ) {
System.out.println("Here is your Chocolate ");
}
else if (choice == 3 ) {
System.out.println("Here is your Popcorn ");
}
else if (choice == 4 ) {
System.out.println("Here is your Juice ");
}
else if (choice == 5) {
System.out.println("3 items of gums sold");
System.out.println("2 items of chocolate sold");
System.out.println("6 items of popcorn sold");
System.out.println("9 items of juice sold");
}
else if (choice== 6)
System.out.println("Stop");
else
System.out.println("Error, Option 1-6 only");
}while (choice<6);
}
}
【问题讨论】:
标签: java