forked from kishanrajput23/Java-Projects-Collections
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChallenge.java
51 lines (47 loc) · 1.47 KB
/
Challenge.java
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
import java.util.Scanner;
public class Challenge {
static boolean isLeapYear(int n) {
if (n % 100 == 0) {
return (n % 400) == 0;
} else {
return n % 4 == 0;
}
}
static int numLYunsorted(int[] a){
int count=0;
for (int j : a) {
if (isLeapYear(j)) {
count++;
}
}
return count;
}
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
System.out.println("Enter the Lower and Upper range.");
System.out.print("\nlower range:");
int l=sc.nextInt();
System.out.print("upper range:");
int u=sc.nextInt();
// int res1=numLYrange(l,u);
System.out.println("Enter no. of years in the sorted list:");
int n=sc.nextInt();
int[] arry = new int[n];
System.out.println("Enter the list of years:");
for(int i=0;i<n;i++){
arry[i]=sc.nextInt();
}
int res1=numLYunsorted(arry);
// int res2=numLYunsorted(arry);
System.out.println("Enter no. of years in the unsorted list:");
int n1=sc.nextInt();
int[] arry1 = new int[n1];
System.out.println("Enter the list of years:");
for(int i=0;i<n1;i++){
arry1[i]=sc.nextInt();
}
int res2=numLYunsorted(arry1);
System.out.println("The difference in both number of years is:"+(res1-res2));
sc.close();
}
}