System.out.println("Here is the list by Category Type.");
System.out.println("Please enter the category you are looking"
+ " for.");
String search = user_input.next();
System.out.println("Here is what we found for that category: ");
for (int row = 0; row < store.length; row++) {
for (int column = 0; column < store[row].length; column++)
if (store[row][column].toUpperCase().contains(search.toUpperCase()))
System.out.println(String.format("%20s\t",store[row][column]));
这是我的代码,用于打印数组中的某些行,但我得到的输出是我不想要的,我不知道如何去做。对于陈述
的部分的示例"Please enter the category you are looking for."
然后我输入:学校用品,它有6个属于该类别的元素,输出打印出来就像这样。
以下是我们在该类别中找到的内容:
School Supplies
School Supplies
School Supplies
School Supplies
School Supplies
School Supplies
我想要显示项目,而不仅仅是类别。
这是我正在查看的数组。
String[][] store = {
{"Alumni Drink ware", "Gifts", "$25.00"},
{"Binders", "School Supplies", "$3.00"},
{"Book bag", "School Supplies", "$20.00"},
{"Fabulous Desserts", "Textbooks", "$25.00"},
{"Folders", "School Supplies", "$1.00"},
{"Gift Cards", "Gifts", "$25.00"},
{"Highlighters", "School Supplies", "$2.00"},
{"Jacket", "Campus Gear", "$65.00"},
{"JAVA Programming", "Textbooks", "$150.00"},
{"Network Solutions", "Textbooks", "$75.00"},
{"Pencils", "School Supplies", "$1.00"},
{"Pens", "School Supplies", "$2.00"},
{"Shorts", "Campus Gear", "$10.00"},
{"Sweatshirts", "Campus Gear", "$40.00"},
{"T-shirts", "campus Gear", "$15.00"},
{"Web Design Ideas", "Textbooks", "$55.00"}};
答案 0 :(得分:0)
System.out.println("Here is the list by Category Type.");
System.out.println("Please enter the category you are looking"
+ " for.");
String search = user_input.next();
System.out.println("Here is what we found for that category: ");
for (int row = 0; row < store.length; row++) {
for (int column = 0; column < store[row].length; column++)
if (store[row][column].toUpperCase().contains(search.toUpperCase()))
System.out.println(String.format("%20s\t", java.util.Arrays.toString(store[row])));