Advertisement
porteno

DigitStorage

Nov 3rd, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1.  
  2. public class DigitStorage {
  3. private int[] count = new int[10];
  4.  
  5. //answer q3.1 - implement a constructor
  6. public DigitStorage(int num) {
  7. while(num>0) {
  8. int digit = num%10;
  9. num /= 10;
  10. count[digit]++;
  11. } //end of while loop
  12. }
  13.  
  14. //answer q3.2
  15. public boolean isSame(DigitStorage other) {
  16. for (int i = 0; i < count.length; i++) {
  17. if(count[i] != other.getCount()[i])
  18. return false;
  19. }
  20. return true;
  21. }
  22.  
  23. public int[] getCount() {
  24. return count;
  25. }
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement