Advertisement
advictoriam

Untitled

Jan 15th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.42 KB | None | 0 0
  1. public class Numbers
  2. {
  3.    /**
  4.       Counts the number of 7s in a given number
  5.       @param num a number >= 0
  6.       @return the number of digits in num that are 7
  7.    */
  8.    public static int countSevens(int num)
  9.    {
  10.       int count = 0;
  11.       String str = Integer.toString(num);
  12.       for(int i = 0; i < str.length(); i++)
  13.       {
  14.          if(str.charAt(i) == '7'){count++;}
  15.       }
  16.       return count;
  17.    }
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement