2015-11-28 57 views
-1
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
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])));