“线程中的异常”;“主要”;java.util.NoSuchElementException:找不到行为什么我在java程序票务服务(队列)中不断获取此错误
给定main(),完成将人员添加到队列的程序。程序应该读入包括“你”(以-1结尾)在内的人名列表,将每个人添加到peopleInQueue队列中。然后,将每个人从队列中移除,直到“你”在队列的最前面。包括打印语句,如下例所示 例如,如果输入为: 扎迪·史密斯 汤姆·索耶 你 路易莎·奥尔科特 输出为: 欢迎来到票务服务。。。 你是队列中的第三名。 扎迪·史密斯买了一张票。 你现在是2号 汤姆·索耶买了一张票。 你现在是第一名 你现在可以买票了“线程中的异常”;“主要”;java.util.NoSuchElementException:找不到行为什么我在java程序票务服务(队列)中不断获取此错误,java,Java,给定main(),完成将人员添加到队列的程序。程序应该读入包括“你”(以-1结尾)在内的人名列表,将每个人添加到peopleInQueue队列中。然后,将每个人从队列中移除,直到“你”在队列的最前面。包括打印语句,如下例所示 例如,如果输入为: 扎迪·史密斯 汤姆·索耶 你 路易莎·奥尔科特 输出为: 欢迎来到票务服务。。。 你是队列中的第三名。 扎迪·史密斯买了一张票。 你现在是2号 汤姆·索耶买了一张票。 你现在是第一名 你现在可以买票了 import java.util.Scanner;
import java.util.Scanner;
import java.util.LinkedList;
import java.util.Queue;
public class TicketingService {
public static void main(String[] args) {
Scanner scnr = new Scanner(System.in);
String personName = "";
int counter = 0;
int youPosition = 0;
Queue<String> peopleInQueue = new LinkedList<String>();
personName = scnr.nextLine();
while (!personName.equals("-1")) {
peopleInQueue.add(personName);
++counter;
if (personName.equals("You")) {
youPosition = counter;
}
personName = scnr.nextLine();
}
System.out.println("Welcome to the ticketing service... ");
System.out.println("You are number " + youPosition + " in the queue.");
for (int i = youPosition - 1; i >= 1; i--) {
System.out.println(peopleInQueue.remove() + " has purchased a ticket.");`enter code here`
System.out.println("You are now number " + i);
}
System.out.println("You can now purchase your ticket!");
}
}
import java.util.Scanner;
导入java.util.LinkedList;
导入java.util.Queue;
公共类票务服务{
公共静态void main(字符串[]args){
扫描仪scnr=新扫描仪(System.in);
字符串personName=“”;
int计数器=0;
int-youPosition=0;
Queue peopleInQueue=新建LinkedList();
personName=scnr.nextLine();
而(!personName.equals(“-1”){
添加(personName);
++计数器;
如果(personName.equals(“You”){
位置=计数器;
}
personName=scnr.nextLine();
}
System.out.println(“欢迎使用票务服务…”);
System.out.println(“您是队列中的数字”+youPosition+”);
对于(inti=youPosition-1;i>=1;i--){
System.out.println(peopleInQueue.remove()+“已购买票证”);`在此处输入代码`
System.out.println(“您现在是编号”+i);
}
System.out.println(“您现在可以购买机票了!”);
}
}