SHARE
TWEET

Untitled

advictoriam Jan 11th, 2019 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import java.util.Scanner;
  2.  
  3. /**
  4.    Counts the number of digits with value 7 in the decimal
  5.    representation of the integer n
  6. */
  7. public class CountSevens
  8. {
  9.    public static void main(String[] args)
  10.    {
  11.       Scanner in = new Scanner(System.in);
  12.       int n = in.nextInt();
  13.       int count = 0;
  14.       String str = Integer.toString(n);
  15.       for(int i = 0; i < str.length(); i++)
  16.       {
  17.          if(str.charAt(i) == '7'){count++;}
  18.       }
  19.      
  20.       System.out.println(count);
  21.    }
  22. }
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