Q:

printing invalid input from string in Java

I am trying to print the invalid number, number which is not of type int or double but not getting desired output, please help me pointing out my mistake and another thing is it is possible to to find out invalid number using some other way?
public class Test {
            public static void main(String [] args)
        {

        String [] str ={ "10.20","30450","12.valid","100.200"};

            for(int i=0; i<str.length; i++)
            {
                if(str[i].indexOf(".")>0)
                {
                    try
                    {
                        Integer.parseInt(str[i]);
                        System.out.println("its a valid int nummber : "+str[i]);
                    }
                    catch(NumberFormatException e)
                    {
                        System.out.println("its invalid number in string: "+str[i]);
                    }
                }
                else
                {
                    try
                    {
                        Double.parseDouble(str[i]);
                        System.out.println("its valid double number: "+str[i]);
                    }

                    catch(NumberFormatException e)
                    {
                        System.out.println("its invalid char in string : "+str[i]);
                    }
                }
            }
        }
    }

output

its invalid number is string: 10.20
its valid double number: 30450
its invalid number is string: 12.valid
its invalid number is string: 100.200

A:

your code inside if/else should be the other way around:
               if(str[i].indexOf(".")>0)
                {
                   ///parse for double
                }
                else
                {
                   //parse for int
                }

