我需要將數組中的所有值複製到3000,這反過來會創建一個新的數組,我將用它來從另一個數組中減去。我試圖創建一個單獨的方法,可以爲我做到這一點,但是我在乘法數組中返回的所有數字和符號都是奇怪的?將數組中的所有元素乘以外部數字?
這裏是我寫的
public static void main(String[] args)
{
int numberOfTaxpayers = Integer.parseInt(JOptionPane.showInputDialog("Enter how many users you would like to calculate taxes for: ");
int[] usernumChild = new int[numberOfTaxPayers];
for (int i = 0; i < usernumChild.length; i++)
{
usernumChild[i] = Integer.parseInt(JOptionPane.showInputDialog("Enter number of children for user "+ (i+1) +": "));
}//this for loop finds out the number of children per user so we can later multiply each input by 3000 to create an array that determine dependency exemption for each user
int[] depndExemp = multiply(usernumChild, 3000);//this was the calling of the multiply method... somewhere here is the error!!
}//end main method
public static int[] multiply(int[] children, int number)
{
int array[] = new int[children.length];
for(int i = 0; i < children.length; i++)
{
children[i] = children[i] * number;
}//end for
return array;
}//this is the method that I was shown in a previous post on how to create return an array in this the dependency exemption array but when I tested this by printing out the dependency array all I received were a jumble of wrong numbers.
你說的「一個新的數組,我將使用來自另一個陣列減去」是什麼意思? – 2013-10-26 15:43:48
@Lutz Horn我還沒有包括那部分,但我需要做的是將依賴性數組(每個輸入乘以3000)從另一個包含每個用戶總收入的數組中減去導致另一個陣列在淨收入下創建...由於某種原因,我們的教師想要爲每種數據類型提供一個陣列 – prodo