Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
55 lines (49 loc) · 1.54 KB

File metadata and controls

55 lines (49 loc) · 1.54 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Program 31
// Week 1 - Day 5
// Note: Two arrays are said to be the same if the sum of both arrays os the same and the size of the array is the same
// Input: Input consist of 2 integers and 2 array. The integer should corrospend to the size of the array
// Output:
//4
//4
//1
//2
//3
//4
//1
//2
//3
//4
import java.util.*;
public class Program31 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter the number of elements in the first array: ");
int n1 = sc.nextInt();
int[] arr1 = new int[n1];
System.out.println("Enter the elements of the first array: ");
for (int i = 0; i < n1; i++) {
arr1[i] = sc.nextInt();
}
System.out.print("Enter the number of elements in the second array: ");
int n2 = sc.nextInt();
int[] arr2 = new int[n2];
System.out.println("Enter the elements of the second array: ");
for (int i = 0; i < n2; i++) {
arr2[i] = sc.nextInt();
}
if (n1 == n2) {
int sum1 = 0, sum2 = 0;
for (int i = 0; i < n1; i++) {
sum1 += arr1[i];
sum2 += arr2[i];
}
if (sum1 == sum2) {
System.out.println("The two arrays are the same.");
} else {
System.out.println("The two arrays are not the same.");
}
} else {
System.out.println("The two arrays are not the same.");
}
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.