再次我貨架我的大腦中的錯誤消息
滾滾而來。我正在學習如何處理數組 - 常規和多維。我有問題a)使用銷售數據填充數組,也使用「無法將字符串轉換爲int」的部分。當我修改這個數組有一個字符串值, - 然後我得到一個翻蓋失敗告終錯誤 - 「不能轉換INT爲String的任何援助表示讚賞感謝不能轉換INT爲String,/不能把字符串轉換成int [] []
public class Sales{
public static void main (String []Args)
{
//a single dimension array containing the following customer names
String [] Names = {"John Doe","Pete BuysAlot","Joe Stingy","Mary LikesOurStuff" } ;
// for(int 0;i<Names.length; i++)
// System.out.printl=n(Names[i]);}
//a single dimension array containing the names of //each month
String[]Months= new String [11];
Months[0] = " Jan ";
Months[1] = " Feb ";
Months[2] = " Mar ";
Months[3] = " Apr ";
Months[4] = " May ";
Months[5] =" June ";
Months[6] =" July ";
Months[7] =" Aug ";
Months[8] =" Sept ";
Months[9] =" Oct ";
Months[10]=" Nov ";
Months[11]=" Dec ";
// this next section creates the variables and data to create and initialize
// a two dimension array that reflects the purchases each person made per month.
//It will have the initial data in the following table
int[][]slsData = { {200,50,30,300,155,220,80,70,95,110,3,400},
{ 1200,2000,1500,900,1300,800,750,500,900,1200,1500,2000},
{10,0,0,20,5,30,10,0,0,10,15,0},
{500,100,200,400,600,200,150,155,220,336,43 ,455}
};
String [][] slsTablePP = slsData[3][Months]; //here is where an error occurance is. [months] is a declared as a new string array but errors.
{
for (int row = 0; row <Names.length; row++)
for (int col = 0; col<Months.length; col++)
System.out.println(slsTablePP[row][col]); }
// array to hold sales figures totals by month
for(int x=0;x<mthlySales-1;x++)
System.out.println(Names[i] + mthlySls[x]);
}
}
}
你的陣列應該是12指數沒有11 – Pratik 2015-04-04 07:00:49
你有什麼打算與'的String [] [] slsTablePP = slsData [3] [月]'會發生什麼? – 2015-04-04 07:04:27
您必須嘗試使用String.valueOf(int)方法並使用數組作爲字符串數組。 – Gopal00005 2015-04-04 07:23:05