-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprog3.java
More file actions
48 lines (38 loc) · 1.09 KB
/
prog3.java
File metadata and controls
48 lines (38 loc) · 1.09 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
/*Given a number N, count the numbers from 1 to N which comprise of digits, only in set 1, 2, 3, 4 and 5.
Input:
Let N be the range of the number.
Output:
Print the count of numbers in the given range from 1 to N.
Constraints:
1 ≤ N ≤ 103
Example:
Input:
100
Output:
30
Explanation:
When N is 20 then answer is 10 because 1 2 3 4 5 11 12 13 14 15 are only in given set. 16 is not beause 6 is not in given set, only 1 2 3 4 5 in set.
*/
import java.util.Scanner;
public class prog3 {
public static void main(String[] args) {
int sum = 0, i;
Scanner sc = new Scanner(System.in);
System.out.println("Inputs:");
int n = sc.nextInt();
System.out.println("Output:");
if (n <= 10) {
System.out.println("5");
} else {
int total = 0;
for (i = 1; i <= n; i++) {
for (int j = 1; j <= 5; j++) {
if (i % 10 == j && i <= 55) {
total = total + 1;
}
}
}
System.out.println(total);
}
}
}