-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharrayHw.java
More file actions
49 lines (46 loc) · 1.34 KB
/
arrayHw.java
File metadata and controls
49 lines (46 loc) · 1.34 KB
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
public class arrayHw {
// 1
public static boolean check_repeat(int nums[]){
for(int i=0;i<nums.length;i++){
for(int j=i+1;j<nums.length;j++){
if (nums[i]==nums[j]){
return true;
}
}
}
return false;
}
// 5
public static int factorial(int n){
int product=1;
for(int i=1;i<=n;i++){
product=product*i;
}
return product;
}
// 5
public static void check(int nums[] ){
int n=nums.length;
for(int i=1;i<n;i++){
for(int j=i+1;j<n;j++){
for(int k=j+1;k<n;k++){
if(factorial(nums[i])==j && factorial(nums[i])==k && factorial(nums[j])==k
&& nums[i]+nums[j]+nums[k]==0){
System.out.println("["+nums[i] +","+ nums[j]+","+ nums[k]);
}
}
}
}
}
public static void main(String args[]){
int nums[]={-1,0,1,2,-1,-4};
// boolean check=check_repeat(nums);
// if (check==true){
// System.out.println("duplicate number true");
// }
// else{
// System.out.println("no any duplicate number False");
// }
check(nums);
}
}