returning data type problem..
hi...all..I am going to construct a meun.And, this meun have 4 choice for it`s user. In other words, the valid value is only within 1 to 4. it is an ivalid value if it is out of the range. Therefore, i implement a function called getInteger( ) to restrict the value...only 1 to 4.. however , i got a strange return after go through my function ..could anyone give me some suggestion..thx ..i have stated my problem in my code ....
import java.util.Scanner;
import java.io.*;
public class Test{
Test()
{
}
private int getInteger(int checkThing, int lowerBound, int upperBound)
{
int aInt = 0;
try
{
while((checkThing < lowerBound ) || (checkThing > upperBound) )
throw new Exception("Invaild value....Please enter the value between " + lowerBound + " & " + upperBound );
}
catch (Exception e)
{
String message = e.getMessage();
System.out.println(message);
//System.exit(0);
// t("Please the value between " + lowerBound + "&" + upperBound );
}
return aInt;
}
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
int userInput;
int outPut;
Test example1 = new Test();
System.out.println("Please enter your value between 1 to 4:");
userInput = scan.nextInt();
System.out.println("Your input is " + userInput);//checking the userInput value
outPut = example1.getInteger(userInput, 1, 4);
System.out.println("Your output is " + outPut); //checking the output value
//Here is my Problem. I could do what i want to do
// when i try to input an invalid value, -1 ,to the program
//The result comes up as the following:
// Your input is -1
//Invaild value....Please enter the value between 1 & 4
// Your output is 0
//But, once i try to input a valid value ,2, to the program
//The result comes up as the following:
//Your input is 2
//Your output is 0 <<- (it should be 2 <_> ....Please help...pls...pls)
//how do i get the return (int) back from the function? what`s wrong with my code?
}
}

