Advertisement
advictoriam

Untitled

Jan 11th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.49 KB | None | 0 0
  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. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement