+ 1

Insert a number like 8662. It shows frequency of 6 two times.How to remove this?

https://code.sololearn.com/cVN4j025iPpx/?ref=app

17th Oct 2017, 2:27 PM
Abhishek Rawat
Abhishek Rawat - avatar
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
17th Oct 2017, 3:15 PM
Chrizzhigh
Chrizzhigh - avatar
+ 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; } //...
17th Oct 2017, 3:15 PM
Chrizzhigh
Chrizzhigh - avatar
+ 2
yeah,I was hoping to solve to solve it without using array but thanks for the advice mate!
17th Oct 2017, 3:15 PM
Abhishek Rawat
Abhishek Rawat - avatar