Advertisement
Yuvalxp8

exercise 22 Page 46

Feb 8th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.85 KB | None | 0 0
  1. import java.util.*;
  2. public class Tar22Page46
  3. {
  4.     public static void getTime(int num,int digit)
  5.     {
  6.         int temp;
  7.         int count = 1 ;
  8.         boolean check = false;
  9.         while(num != 0)
  10.         {
  11.             temp = num % 10;
  12.             if(temp==digit)
  13.             {
  14.                 System.out.print(count + " ");
  15.                 check=true;
  16.             }
  17.             num= num / 10;
  18.             count++;
  19.         }
  20.         if(!check)
  21.             System.out.print("None");
  22.     }
  23.     public static Scanner in = new Scanner(System.in);
  24.     public static void main(String []args)
  25.     {
  26.         System.out.println("Enter a num ");
  27.         int num = in.nextInt();
  28.         for(int i=0;i<=9;i++)
  29.         {
  30.             System.out.print(i + " is: ");
  31.             getTime(num,i);
  32.             System.out.println();
  33.         }
  34.     }
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement