I'm trying to make it for that the program will continue to request input of a 5 digit number until the user gives a 5 digit number. When I run the following:
//import scanner to read keyboard input
import java.util.Scanner;
class NumberInverter {
public static void main(String[] args) {
//create a new Scanner object in the memory that reads from the input System.in
Scanner keyboard = new Scanner(System.in);
//display message propmt and input for number
//conditional statement loop to check if the length is any number other than 5
do {
System.out.print("Enter any 5 digit whole number you wish to invert!");
int num = keyboard.nextInt();
int numSize = String.valueOf(num).length();
} while(!isValid(numSize));
}
private static boolean isValid(int numSize){
if(numSize != 5){
System.out.println("Oops! Looks like you gave a number that isn't exactly a 5 digit whole number. Try again!");
return false;
} else return true;
}
}
I get the following error:
NumberInverter.java:20: error: cannot find symbol
} while(!isValid(numSize)); ^
symbol: variable numSize
location: class NumberInverter
1 error
I've tried a bunch of different things, can anyone fluent in java help me out I'm very new? Thanks ahead of time!