Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Subtracting two arrays (variables with decimals)

How to subtract the below two arrays in java?

(09.34, 09.56, 09.00, 08.55 )
(17.25, 18.06, 17.55, 16.00)

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

class MainClass {
    public static void main(String[] args) {
        double[] d1 = {09.34, 09.56, 09.00, 08.55};
        double[] d2 = {17.25, 18.06, 17.55, 16.00};

        int operations = d1.length>d2.length? d2.length: d1.length;

        int noOfElements = d1.length<d2.length? d2.length: d1.length;
        double[] result = new double[noOfElements];

        for (int x=0; x<operations; x++){
            result[x] = d1[x] - d2[x];
            System.out.println(result[x]);
        }
    }
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading