dm6801

20171113 - 03 - classEx_02

Nov 13th, 2017
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.71 KB | None | 0 0
  1. package myApp;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class class03_ex08 {
  6.  
  7.     public static void main(String[] args) {
  8.         //init vars
  9.         final int   TIMES = 3;
  10.        
  11.         int         n = 0,
  12.                     nLength = 0;
  13.        
  14.         //open in_stream
  15.         Scanner s = new Scanner(System.in);
  16.        
  17.         //usage info
  18.         System.out.printf("Type in %d digits: ", TIMES);
  19.        
  20.         //nLength holds n's digit count
  21.         while (nLength != TIMES) {
  22.             nLength = 0; //reset counter from last iteration
  23.             n = s.nextInt(); //accept new n value
  24.            
  25.             //calc digit count
  26.             for (int i=n; i>0; i /= 10) {
  27.                 nLength += 1;
  28.             }
  29.            
  30.         }
  31.                
  32.         //close in_stream
  33.         s.close();
  34.        
  35.         //exit msg
  36.         System.out.printf("number %d accepted. exit..%n", n);
  37.        
  38.     }
  39.  
  40. }
Add Comment
Please, Sign In to add comment