0
     try{
           name= JOptionPane.showInputDialog("Enter Employee Name: ");
            }
            <br />
        catch (Exception e){
         //wHAT IS THE CODE HERE if  THE INPUT IS NUMERIC
         JOptionPane.showInputDialog("Invalid Input");
       }
2
Contributors
5
Replies
6
Views
4 Years
Discussion Span
Last Post by lloydsbackyard
0

Well here is one solution:

public class IsItAnInt {
    public static boolean isInt(String number){
        try{
            int a = Integer.parseInt(number);
            return true;
        }
        catch(Exception evt){
            return false;
        }
    }

    public static void main(String[] args){
        System.out.println("is 12 an int? : " + isInt("12"));
        System.out.println("is 1234fd an int?: " + isInt("1234fd"));
    }
}

You can use the isInt method to find out whether it is in int or not. Also take out the <br />, this is Java not HTML.

0
 try{
           name= JOptionPane.showInputDialog("Enter Employee Name: ");
            }
        catch (Exception e){
         //wHAT IS THE CODE HERE if  THE INPUT IS NUMERIC instead of STRING since name is string...
         JOptionPane.showInputDialog("Invalid Input");
       }
0

I just gave you the method, just use isInt() method. Take out the try and catch and use an if/else statement.

Edited by godzab

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.