hi In my program if I enter number in the field it should display as valid value and if I enter alphabets or special characters it should be displayed as invalid value ,but when i run the following code it displays error if I enter words as input and If i enter number it is displaying correct format
package quantity;
import java.util.Scanner;
public class Quantity {
public static void main(String[] args) {
Scanner input =new Scanner(System.in);
System.out.println("enter input");
double qty = input.nextDouble();
System.out.println(" input ="+qty);
if(!("[_a-z_A-Z_)+").equals("qty")||
!("[_!_~_@_#_$]").equals("qty"))
{
System.out.println("correct format");
}
// TODO code application logic here
else
{
System.out.println("wrong input");
}
}
}
following errors are displayed for words
Exception in thread "main" java.util.InputMismatchException
at java.util.Scanner.throwFor(Scanner.java:864)
at java.util.Scanner.next(Scanner.java:1485)
at java.util.Scanner.nextDouble(Scanner.java:2413)
at quantity.Quantity.main(Quantity.java:19)