-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram13.java
More file actions
29 lines (23 loc) · 741 Bytes
/
Program13.java
File metadata and controls
29 lines (23 loc) · 741 Bytes
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
// Day 3 - Week 1
// Write a program to count odd digit numbers from 1 to 110.
public class Program13 {
public static void main(String[] args) {
int oddcount = 0;
int evencount = 0;
for (int i = 1; i <= 110; i++) {
int num = i;
int digitCount = 0;
while (num > 0) {
num /= 10;
digitCount++;
}
if (digitCount % 2 != 0) {
oddcount++;
} else {
evencount++;
}
}
System.out.println("Count of odd digit numbers from 1 to 110: " + oddcount);
System.out.println("Count of even digit numbers from 1 to 110: " + evencount);
}
}