简体   繁体   English

java中将两个数组中的数字相乘

[英]Multiplying numbers in two arrays in java

I want to multiply the numbers of two arrays in java.我想在java中将两个数组的数字相乘。 I declared two array objects.我声明了两个数组对象。 a for getting xValue and b for getting yValue.. After putting values of x and y for n programs each time value of x and y should be multiplied. a 用于获取 xValue 和 b 用于获取 yValue.. 在将 x 和 y 的值放入 n 个程序之后,每次 x 和 y 的值都应该相乘。 Please show me the code.. import java.util.*;请给我看代码.. import java.util.*;

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()); 



}  
}

///////////////////////////// /////////////////////////////

Class for DataSet数据集类

import java.util.ArrayList;   
import java.util.List;   


public class DataSet {   

    private List<Double> 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();   

    }   
}

Actually I want to make formaula.其实我想做公式。 I want to get value of x*y , x^2 and y^2.我想获得 x*y 、 x^2 和 y^2 的值。 I am very sorry I am new to JAVA language and dont know how to do that.我很抱歉我是 JAVA 语言的新手,不知道该怎么做。

Being so new to java, you use arraylist's to do simple arithmetic?对 java 这么陌生,你用 arraylist 来做简单的算术吗? What is this used for?这是做什么用的?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM