In this Tutorial we explain an example from Argument exception in java .Exceptions are the condition in Java to indicate a calling method that an abnormal condition has occurred. This tutorial describes how to handle Argument exceptions appropriately in your programs. The steps involved in the program are described below:-
private static Scanner key = new Scanner(System.in):-Here we are declaring Scanner class object. Scanner is a class which is used to parse primitive types and strings using regular expressions.
Input = key. next():-This is the method by which we can find and returns the next complete token from this scanner.
System.out.println(Input + " is not an Integer value" + "\n"+ "Please enter appropriate value"):-This is the Exception message which is to be displayed if the number you entered is not a real number.
Output of the program
|Please enter a real number : Girish
Girish is not an Integer value
Please enter apporipriate value
Liked it! Share this Tutorial
Ask Questions? Discuss: Example to show Argument Exception in java
Post your Comment