+ 1
Insert a number like 8662. It shows frequency of 6 two times.How to remove this?
3 Answers
+ 3
you have to remember which number you already printed.
for that you could use a array or a list and check if the number already occured
eg
int[] a = new int[10];
lets say the number is a 2 than you
check
if (a[2] == 0){
a[2] = 1;
//do stuff (your while loop for example)
}
//rest of code to skip the number
+ 2
in your example:
//...
//start new code
int[] used = new int[10];
//end new code
while(e>0)
{
a=e%10;
//start new code
if(used[a] == 0){
used[a] = 1;
while(b>0)
{
c=b%10;
if(a==c)
d++;
b=b/10;
}
System.out.println("Frequency of "+a+" = "+d);
}
//end of new code
e=e/10;
b=n;
d=0;
}
//...
+ 2
yeah,I was hoping to solve to solve it without using array but thanks for the advice mate!