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 :
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]);
}
}
}