Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- /**
- Counts the number of digits with value 7 in the decimal
- representation of the integer n
- */
- public class CountSevens
- {
- public static void main(String[] args)
- {
- Scanner in = new Scanner(System.in);
- int n = in.nextInt();
- int count = 0;
- String str = Integer.toString(n);
- for(int i = 0; i < str.length(); i++)
- {
- if(str.charAt(i) == '7'){count++;}
- }
- System.out.println(count);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement