Sunday 11 August 2013

Java Program: Find the given string from the user is integer or not

// siddhu vydyabhushana // 4 comments

java program to find whether our given input is string or numeric value, in java there is no direct function to identify the given input is numeric or not below program shows how to identify the string into numeric.



class CheckValue 
{
    public boolean checkIfNumber(String in) {

        try {

            Integer.parseInt(in);

        } catch (NumberFormatException ex) 
        {
            return false;
        }

        return true;
    }
    public static void main(String[] args) 
    {
        String str="22222";
        CheckValue v=new CheckValue();
        boolean value=v.checkIfNumber(str);
        if(value){
            System.out.println("Value is integer!");
        }
        else{
            System.out.println("Value is not integer!");
        }

    }
}
Your likes and shares makes me more happy

4 comments: