-
Notifications
You must be signed in to change notification settings - Fork 0
/
For_Loops.java
39 lines (39 loc) · 1.05 KB
/
For_Loops.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
public class For_Loops {
public static void main(String[] args) {
int[] nums = {3, -4, 2, 124, 8, 10, 5};
System.out.println(howManyBy3());
System.out.println(howManyBy3TheSequel(6));
System.out.println(parityDistribution(nums));
}
public static int howManyBy3() {
int count = 0;
for (int i = 1; i <= 1000; i++) {
if (i%3 == 0) {
count++;
}
}
return count;
}
public static int howManyBy3TheSequel(int n) {
int count = 0;
for (int i = 1; i <= n; i++) {
if (i%3 == 0) {
count++;
}
}
return count;
}
public static String parityDistribution(int[] arr) {
int even = 0;
int odd = 0;
for (int i = 0; i < arr.length; i++) {
if (arr[i] % 2 == 0) {
even++;
} else {
odd++;
}
}
String evenAndOdd = "Even: " + even + "\n" + "Odd: " + odd;
return evenAndOdd;
}
}