Advertisement
yanivtamari

29.05 function (1)

May 29th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.60 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4.  
  5.     public static int numbers(int number, int digit) {
  6.         int res = 0;
  7.         while (number > 0) {
  8.             if (number % 10 == digit) {
  9.                 res += 1;
  10.             }
  11.             number /= 10;
  12.         }
  13.         System.out.println(res);
  14.         return res;
  15.     }
  16.         public static void main (String[]args){
  17.             Scanner s = new Scanner(System.in);
  18.             System.out.println("please enter a number");
  19.             int num = s.nextInt();
  20.             int digi = s.nextInt();
  21.             numbers(num, digi);
  22.         }
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement