That explains the *'s >.<
Exception handling in Java is very easy, just gets some getting used to. Scanner's nextInt call will throw a NoSuchElementException, IllegalStateException or InputMismatchException.
What you want is not to toss an exception, rather to catch it. This is done quite simply with:
PHP Code:
int number = 0;
try
{
number = sc.nextInt();
}
catch (Exception ex)
{
System.out.println("Invalid entry!");
}
Combine that with a do/while loop and some flushing:
PHP Code:
boolean isGood = false;
int number;
do
{
try
{
System.out.print("Enter Required Line Number: ");
number = sc.nextInt();
isGood = true;
}
catch (Exception ex)
{
System.out.println("Invalid entry!");
sc.nextLine();
}
} while (!isGood);
// Process it.