File tree 1 file changed +51
-0
lines changed
1 file changed +51
-0
lines changed Original file line number Diff line number Diff line change
1
+ import java .util .Scanner ;
2
+ public class Challenge {
3
+ static boolean isLeapYear (int n ) {
4
+ if (n % 100 == 0 ) {
5
+ return (n % 400 ) == 0 ;
6
+ } else {
7
+ return n % 4 == 0 ;
8
+ }
9
+ }
10
+ static int numLYunsorted (int [] a ){
11
+ int count =0 ;
12
+ for (int j : a ) {
13
+ if (isLeapYear (j )) {
14
+ count ++;
15
+ }
16
+ }
17
+ return count ;
18
+ }
19
+ public static void main (String [] args ){
20
+ Scanner sc = new Scanner (System .in );
21
+
22
+ System .out .println ("Enter the Lower and Upper range." );
23
+ System .out .print ("\n lower range:" );
24
+ int l =sc .nextInt ();
25
+ System .out .print ("upper range:" );
26
+ int u =sc .nextInt ();
27
+ // int res1=numLYrange(l,u);
28
+
29
+ System .out .println ("Enter no. of years in the sorted list:" );
30
+ int n =sc .nextInt ();
31
+ int [] arry = new int [n ];
32
+ System .out .println ("Enter the list of years:" );
33
+ for (int i =0 ;i <n ;i ++){
34
+ arry [i ]=sc .nextInt ();
35
+ }
36
+ int res1 =numLYunsorted (arry );
37
+ // int res2=numLYunsorted(arry);
38
+ System .out .println ("Enter no. of years in the unsorted list:" );
39
+ int n1 =sc .nextInt ();
40
+ int [] arry1 = new int [n1 ];
41
+ System .out .println ("Enter the list of years:" );
42
+ for (int i =0 ;i <n1 ;i ++){
43
+ arry1 [i ]=sc .nextInt ();
44
+ }
45
+ int res2 =numLYunsorted (arry1 );
46
+
47
+ System .out .println ("The difference in both number of years is:" +(res1 -res2 ));
48
+
49
+ sc .close ();
50
+ }
51
+ }
You can’t perform that action at this time.
0 commit comments