slaamz guls and guys!

can any body tell ,how to validate input to check whether it in Integer only?? it shouldnot be in Double, Long and float in type..... i am writting simple code for simple calculator.... plz reply me fast if any body knows...

regards
m0m0

Recommended Answers

All 3 Replies

You can call the Integer.parseInt(String) method and if it throws an exception then it is not an int.

thank you ...i have done it before....as

st1=JOptionPane.showInputDialog("Enter Value for 'x'");
       st2=JOptionPane.showInputDialog("Enter Value for 'y'");

      int x= Integer.parseInt(st1);
      int y= Integer.parseInt(st2);

        int sum = x+y;

       JOptionPane.showMessageDialog(null,"Sum of x and y is" +sum);

it throws exception as well. but i want to throw my own exception.

Do you know how to use try-catch?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.