查找库存量少于10件的所有商品(Find all items with less than 10 items in stock)

编程入门 行业动态 更新时间:2024-10-21 13:22:27
查找库存量少于10件的所有商品(Find all items with less than 10 items in stock)

我正在尝试制作此库存计划。 在我的交换机的情况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.. }

更多推荐

本文发布于:2023-07-14 20:38:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1107265.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:库存量   商品   stock   Find   items

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!