-2
我一直停留在這個計劃了一段時間搜索字符串我必須做出一個程序,當用戶輸入的項目和門店數量將會給量在二維數組
import java.util.Scanner;
public class Searching {
public static void main(String[] args) {
String firstarray[][] = {
{"", "Store101", "Store102", "Store103", "Store104"},
{"Tennis Shoes", "102", "54", "20", "78"},
{"Sweaters", "45", "25", "35", "75"},
{"Jeans", "12", "35", "45", "65"},
{"Shorts", "54", "25", "34", "45"},
{"Jackets", "15", "35", "50", "25"}
};
Scanner input = new Scanner(System.in);
System.out.println("Enter item");
String userintake = input.next();
System.out.println("Enter Store Number");
String store = input.next();
searchingitem(firstarray, userintake, store);
}
private static void searchingitem(String x[][], String item, String place) {
for (int i = 0; i < x.length; i++) {
for (int j = 0; j < x[i].length; j++) {
if ((item.equals(x[i][j])) || (place.equals(x[i][j]))) {
int row = i;
int column = j;
printArray(x, i, j);
}
}
}
}
public static void printArray(String x[][], int product, int place) {
for (int row = 0; row < 1; row++) {
for (int column = 0; column < 1; column++)
System.out.print(x[product][place] + "\t");
}
}
}
當我運行該程序輸出我輸入的單詞,而不是數量。我使用搜索方法,它確實給出了正確的數字,但是當它打印時,它不會打印正確的答案,對於我能做些什麼來解決問題有幫助?
@ user3373392:請標記爲答案,如果它做了這項工作。 –