大家好,所以当我尝试访问代码时会发生以下情况,第一部分很好,因为没有库存中的手提包我希望它说你正在携带但是如果我有手提包我希望它说你正在携带这些物品在您的手提包中,但会发生以下情况;
现在怎么办?拿到手电筒好
现在怎么办?您携带的清单:手电筒
现在怎么办?走楼梯 这里很黑!
现在怎么办?拿到手提包好
What now?
list
You are carrying these items in your handbag:
torch
You are carrying these items in your handbag:
wallet
You are carrying these items in your handbag:
keys
You are carrying these items in your handbag:
ring
You are carrying these items in your handbag:
USB
You are carrying these items in your handbag:
mobile
You are carrying these items in your handbag:
handbag
这是代码
public void listWhatYouHave()
{
for (int i = 0; i < 7; i++)
{
if (hasItem[6])
{
System.out.println("You are carrying these items in your handbag:");
switch (i)
{
case 0:
System.out.println("torch");
break;
case 1:
System.out.println("wallet");
break;
case 2:
System.out.println("keys");
break;
case 3:
System.out.println("ring");
break;
case 4:
System.out.println("USB");
break;
case 5:
System.out.println("mobile");
break;
case 6:
System.out.println("handbag");
break;
default:
System.out.println("invalid item!");
break;
}
}
else if (hasItem[i])
{
System.out.println("You are carrying:");
switch (i)
{
case 0:
System.out.println("torch");
break;
case 1:
System.out.println("wallet");
break;
case 2:
System.out.println("keys");
break;
case 3:
System.out.println("ring");
break;
case 4:
System.out.println("USB");
break;
case 5:
System.out.println("mobile");
break;
case 6:
System.out.println("handbag");
break;
default:
System.out.println("invalid item!");
break;
}
}
}
你能帮忙...谢谢(这显然是java)
抱歉,模糊不清...几乎当我没有手提包时,我希望它通过说“您正在携带”来列出我携带的物品,但是如果我在拿起手提包的时候拿起手提包...我希望它说“你的手提包里有这些物品”,但目前它打印出你只携带一次......但是你在手提包里携带这些物品被印在每一行......我只想要一次。