SHARE
TWEET

Untitled

advictoriam Jan 15th, 2019 50 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top