我真的坚持这个。我必须创建一个手机计划插件菜单。然后我必须编写一个 java 代码段,它将显示这些选项的菜单并循环以允许用户选择所需的选项,直到用户输入 -1。这是我到目前为止所拥有的:
import java.util.Scanner;
public class CellPhone {
public static void main(String[] args) {
//new array
String [] plans = new String[4];
plans[0] = "a. 200 or less text messages a month: $5.00";
plans[1] = "b. Additional line: $9.99";
plans[2] = "c. International calling: $3.99";
plans[3] = "d. Early nights and weekends: $16.99";
System.out.println("Here are your plan options: ");
//outputs the contents of the array
for(int i = 0; i < 4; i++) {
System.out.println(plans[i]);
}
// Sentinel loop for adding options
final String SENTINEL = "-1";
String choices = plans[0];
Scanner scanner = new Scanner(System.in);
System.out.println("What would you like to add to your plan (options are a,b,c, or d. Enter -1 when you are finished): ");
String yourChoice = scanner.nextLine();
while (yourChoice != SENTINEL) {
}
}
}
我究竟如何才能做到这一点,我需要在 while 循环中放入什么?谢谢!