I need to write a program that accepts the following conditions:
- It has to be an odd number,
- Have an odd number of digits,
- All of its digits have to be odd numbers and
- The number has to be between 101 and 1000001.
I am currently stuck on trying to check if it has an odd number of digits. Any help would be appreciated. Update: Thanks for all the help everyone. It was really helpful!
import java.util.Scanner;
public class TestOddNumbers {
public static void main(String[] args) {
Scanner stdin = new Scanner(System.in);
int userInput;
final int EXIT = -1;
final int MIN = 101;
final int MAX = 1000001;
do{
System.out.println("please enter a positive whole number between"
+ "" + MIN + " and " + MAX + ". Enter " + EXIT + " "
+ "when you are done entering numbers.");
userInput = stdin.nextInt();
}
while(userInput != EXIT && userInput >= MIN && userInput <= MAX);
if(userInput % 2 == 1){
System.out.println("This is an odd number");
}
else{
System.out.println("This is not an odd number");
}
}
}
}