Use a while
loop in your get
methods e.g. to repeatedly ask for input until a valid number is entered.
public static int getNum() //Get amount of numbers to check
{
Scanner input = new Scanner ( System.in );
System.out.print( "How many numbers would you like to test? " );
int count = input.nextInt();
int perfect = 1;
boolean vN = validateNum(count, perfect);
while(!vN ){
System.out.println("Invalid input. Try again");
count = input.nextInt();
vN = validateNum(count, perfect);
}
return count;
}
Simiilarly, update the getPerfect
method and remove int count = getNum();
statement from this method.
EDIT: To repeatedly ask for perfect number count
times, update your main method as below:
public static void main ( String args [] )
{
int gN = getNum();
for(int indx=0; indx <gN; indx++){
int gP = getPerfect();
//use your gP numbers in the way you want
}
}
EDIT1: To call How many numbers would you like to test? "
tow times, I think you can simply call your getNum()
method two times in the main method as below:
public static void main ( String args [] )
{
int gN = getNum();//first call
gN = getNum(); //second call
int gP = getPerfect();
}