Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package myApp;
- import java.util.Scanner;
- public class class03_ex10 {
- public static void main(String[] args) {
- //init vars
- final int TIMES = 3;
- final int MOD = 3;
- int n = 0,
- nLength = 0;
- //open in_stream
- Scanner s = new Scanner(System.in);
- //usage info
- System.out.printf("Type in %d digits: ", TIMES);
- //nLength holds n's digit count
- while (nLength != TIMES || (n % MOD != 0)) {
- nLength = 0; //reset counter from last iteration
- n = s.nextInt(); //accept new n value
- //calc digit count
- for (int i=n; i>0; i /= 10) {
- nLength += 1;
- }
- }
- //close in_stream
- s.close();
- //exit msg
- System.out.printf("number %d accepted. exit..%n", n);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment