Advertisement
Shavit

P. 187 Ex. 7.40 B

Nov 8th, 2013
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.46 KB | None | 0 0
  1. // Shavit Borisov
  2. // CW
  3.  
  4. import java.util.Scanner;
  5.  
  6. public class DigitCount {
  7.  
  8.     public static void main(String[] args)
  9.    
  10.     {
  11.         Scanner in = new Scanner (System.in);
  12.        
  13.         int digits = 0;
  14.         int num;
  15.        
  16.         System.out.print("Enter a number: ");
  17.         num = in.nextInt();
  18.        
  19.         while(num > 0)
  20.         {
  21.             if(num % 2 == 1)
  22.                 digits++;
  23.            
  24.             num = num / 10;
  25.         }
  26.        
  27.         System.out.printf("The number of odd digits is %d", digits);
  28.        
  29.         in.close();
  30.     }
  31.    
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement