【发布时间】:2013-11-05 16:15:56
【问题描述】:
我需要将数组中的所有值乘以 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.
【问题讨论】:
-
“我将用来从另一个数组中减去的新数组”是什么意思?
-
@Lutz Horn 我还没有包含那个部分,但是我要做的是获取依赖数组(每个输入将孩子乘以 3000),然后从另一个包含每个用户的总收入,这将导致在净收入下创建另一个数组......出于某种原因,我们的讲师想要每个数据类型的数组