-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain18.java
More file actions
38 lines (27 loc) · 942 Bytes
/
Main18.java
File metadata and controls
38 lines (27 loc) · 942 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
30
31
32
33
34
35
36
37
38
package loopinjava;
import java.util.Scanner;
public class Main18 {
public static void main(String[] args) {
int i, count, digit, number, numberClone;
Scanner input = new Scanner(System.in);
System.out.println("Find frequency of each digit in a given integer.\n");
System.out.print("Enter a number: ");
number = input.nextInt();
numberClone = number;
for (i = 0; i <= 9; i++) {
count = 0;
number = numberClone;
while (number != 0) {
digit = (number % 10);
number = (number / 10);
if (digit == i) {
count++;
}
}
/// if(count > 0) /** This line will be print, if frequency is greater than 0.*/
{
System.out.println("Frequency of " + i + " = " + count);
}
}
}
}