forked from krimanisha/Hacktoberfest21
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCountNums.java
More file actions
23 lines (19 loc) · 818 Bytes
/
CountNums.java
File metadata and controls
23 lines (19 loc) · 818 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import java.util.Scanner;
public class CountNums {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.print("Enter a number:");
int n = in.nextInt(); //this will take input from user
System.out.print("Enter number to count:");
int a = in.nextInt(); //this will take number that we need to find
int count = 0;
while(n>0){
int rem = n % 10; //this will give the remainder
if (rem == a){
count++; //this will increment if the remainder is equal to the required number
}
n=n/10; //this will divide the input with 10
}
System.out.println(count);
}
}