【发布时间】:2015-10-27 11:21:08
【问题描述】:
我正在制作一个增强的 for 循环来对我的零件数组列表中的零件对象进行排序。但是,当增强的 for 循环进入 if 语句时,它什么也不做(Damper 除外)并且没有错误,所以我不知道为什么它不起作用。 thelist 是我保存对象的数组列表的名称。
for(int z=0; z<20; z++){
displayMenu();
int selection = sc.nextInt();
if(selection == 0){
System.out.println("You have exited the system");
} else if(selection == 1){
System.out.println("Choose stock name to replenish");
for(Part y: thelist){
String nS = sc.nextLine();
System.out.print(nS);
if(nS.equals(y.getName())){
System.out.println("Please enter replenish quantity");
int qty = sc.nextInt();
y.replenish(qty);
System.out.println("Complete");
}
}
} else if
我的对象
Part part0 = new Part("p100", "Spring", 43, 120);
Part part1 = new Part("p101", "Damper", 72, 150);
Part part2 = new Part("p102", "Lower CA", 38, 80);
Part part3 = new Part("p103", "Upper CA", 26, 70);
只是为了展示这一点 'String nS' 工作中
此外,它仅适用于阻尼器
【问题讨论】:
标签: java if-statement for-loop getter