我正在尝试制作此库存计划。 在我的交换机的情况4中,我试图从我的库存文本文件中查找少于10个库存项目的所有项目。 到目前为止,我只能找到具有最低数量项目的项目,当我需要所有项目少于10时。我们非常感谢所有帮助。 我在这个网站上的第一个问题,所以我希望你对我很温柔哈哈。 :)
case 4: int lowest = 10; for( int i = 0; i < allItems.length; i++) { if( allItems[i].getNumberOfPieces() < allItems[lowest].getNumberOfPieces()) lowest = i; } System.out.println("\nThe items that have less than 10 pieces in stock: " + allItems[lowest]); break;再次,这是我的第一个问题,我很抱歉,如果它没有得到很好的问。
I am trying to make this inventory program. In case 4 of my switch I am trying to find all items from my inventory text file that have less than 10 items in stock. So far I am only able to find the item with the single lowest number of items, when I need all items with less than 10. Any help is greatly appreciated. My first question on this site so I hope you are gentle with me haha. :)
case 4: int lowest = 10; for( int i = 0; i < allItems.length; i++) { if( allItems[i].getNumberOfPieces() < allItems[lowest].getNumberOfPieces()) lowest = i; } System.out.println("\nThe items that have less than 10 pieces in stock: " + allItems[lowest]); break;Again, this is my first question and I apologize if it is not well asked.
最满意答案
不是找到最小值,这不是你真正想要的,只要你发现它小于10就可以输出库存项目。这样可以为你节省制作数据结构的麻烦,除非你想使用该名单再次。
for( int i = 0; i < allItems.length; i++) { int pieces = allItems[i].getNumberOfPieces(); if( pieces < 10) System.out.println(pieces); //or whatever you'd like to print related to this index.. }Instead of finding the minimum, which is not really what you want, you could output the inventory item as soon as you find it to be less than 10. This would also save you the hassle of making a data structure, unless you want to use the list later again.
for( int i = 0; i < allItems.length; i++) { int pieces = allItems[i].getNumberOfPieces(); if( pieces < 10) System.out.println(pieces); //or whatever you'd like to print related to this index.. }更多推荐
发布评论