Skip to content

Commit a935632

Browse files
Merge pull request #232 from jayyuuuu/patch-2
Create DoubleArrayCompair.java
2 parents 4536bc8 + 79156f8 commit a935632

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

DoubleArrayCompair.java

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Java program to compare two double arrays
2+
3+
import java.util.*;
4+
import java.lang.*;
5+
import java.io.*;
6+
7+
class GFG {
8+
9+
public static void main(String[] args) throws java.lang.Exception
10+
{
11+
// Two double arrays array1 and array2
12+
double[] array1 = { 1.5, 2.5, 3.5, 4.5 };
13+
double[] array2 = { 1.5, 2.5, 3.5 };
14+
15+
// when the length of two arrays are not
16+
// same, then both the arrays cannot be equal
17+
// so no need of comparing each element
18+
if (array1.length != array2.length)
19+
20+
System.out.println("Arrays are not Equal");
21+
22+
else {
23+
for (int i = 0; i < array1.length; i++)
24+
{
25+
// comparing each and every element
26+
if (array1[i] != array2[i])
27+
{
28+
System.out.println("Arrays are not Equal");
29+
System.exit(0);
30+
}
31+
}
32+
33+
System.out.println("Arrays are Equal");
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)