java 扫描系统_Java多个扫描仪

我有一个类创建多个Integer对象并将它们放入LinkedList,如下所示:

public class Shares implements Queue {

protected LinkedList L;

public Shares() {

L = new LinkedList();

}

public boolean add(E price) {

System.out.println("How many of these shares would you like?");

Scanner scanInt;

scanInt = new Scanner(System.in);

Integer noShares = scanInt.nextInt();

for (int i = 0; i < noShares; i++) {

L.addLast(price);

}

scanInt.close();

return true;

}

}

我有一个应用程序从控制台扫描输入“添加”,如果找到,调用方法添加如下所示:

public class Application {

private static Scanner scan;

public static void main(String[] args) {

Queue S = new Shares();

scan = new Scanner(System.in);

System.out.println("Please type add");

String sentence = scan.nextLine();

while (sentence.equals("quit") == false) {

if (sentence.equals("add")) {

System.out

.println("What price would you like to buy your shares at?");

S.add((Integer) scan.nextInt());

} else

System.exit(0);

sentence = scan.nextLine();

}

}

}

应用程序应允许用户根据需要多次输入“添加”,但在调用add方法后出现错误“no line found”.

我猜这是因为方法中的扫描仪尚未关闭,然后在需要时重新打开.这是程序出了什么问题,如果是这样,我该如何修复它?

请注意,此程序尚未完成,因为我将添加销售这些股票的销售方法.这就是我使用while循环的原因.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值