Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Numbers
- {
- /**
- Counts the number of 7s in a given number
- @param num a number >= 0
- @return the number of digits in num that are 7
- */
- public static int countSevens(int num)
- {
- int count = 0;
- String str = Integer.toString(num);
- for(int i = 0; i < str.length(); i++)
- {
- if(str.charAt(i) == '7'){count++;}
- }
- return count;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement