我想在java中乘以两个数组的数字。我声明了两个数组对象。 a获得xValue和b获取y值。在为n个程序添加x和y的值后,每次x和y的值应该相乘。请给我看代码.. import java.util。*;在java中的两个数组中乘以数字
public class DataSetTesterN {
public static void main(String[] args)
{
DataSet a = new DataSet();
// Object "a" for xValue"
DataSet b = new DataSet();
// Object "b" for yValue"
Scanner input=new Scanner(System.in);
System.out.println("enter the total number of Programs");
int m =input.nextInt();
for(int i =1; i <=m; i++)
// Entering total number of tested program.
{
System.out.println("enter x value for the program no. "+i+"");
a.add(input.nextInt());
// Getting an input for xValue.
System.out.println("enter y value for the program no. "+i+"");
b.add(input.nextInt());
// Getting an input for yValue.
}
System.out.println("count x: " + a.getCount());
System.out.println("count y: " + b.getCount());
System.out.println("Mean x: " + a.getMean());
System.out.println("Mean y: " + b.getMean());
System.out.println("Sum x: " + a.getSum());
System.out.println("Sum y: " + b.getSum());
System.out.println("standard deviation: " + a.getStandardDeviation());
System.out.println("standard deviation: " + b.getStandardDeviation());
}
}
/
类为数据集
import java.util.ArrayList;
import java.util.List;
public class DataSet {
private List inputList = new ArrayList();
double x = 0;
public DataSet() {
}
public void add(double x) {
inputList.add(x);
}
public double getMean() {
double sum = getSum();
double count = getCount();
double mean = sum/count;
return mean;
}
public double getSum() {
double sum = 0;
for (double d : inputList) {
sum += d;
}
return sum;
}
public double getStandardDeviation() {
double sum = getSum();
double mean = getMean();
double calc1 = 0;
double calc2 = 0;
double count = getCount();
double stdDeviation = 0;
//System.out.println("Sum = " + sum);
for (int i = 0; i < count; i++) {
calc1 = inputList.get(i) - mean;
calc1 = Math.pow(calc1, 2);
calc2 = calc2 + calc1;
}
calc2 = calc2/(count-1);
stdDeviation = Math.sqrt(calc2);
return stdDeviation;
}
public int getCount() {
return inputList.size();
}
}
其实我想做formaula。我想要得到x * y,x^2和y^2的值。 非常抱歉,我是JAVA语言的新手,不知道该怎么做。
+2
什么是DataSet?你想如何增加数组?请发表一个例子。 –
+2
你是什么意思“乘以两个数组的数量”?这可以用几种不同的方式解释 - 请举个例子。 –
+1
“我宣布了两个数组对象” - 无法在代码示例中看到它们... –