-6
String texts;
texts = textFieldb.getText();
String textd;
textd = textFieldc.getText();

How would I get it to run a specific function using " if ", example : If 'texts' is a number then it'll run a specific function, and if it wasn't a number, it would run another. Also, how would I do that if it's a word, rather then a number? Thanks. :)

C_Tee
  • 13
  • 2

1 Answers1

0

I think it's really simple. You just need to parse your String and catch the exception. If it's in the exception, that's not a number, then you can do any business you want. For example:

    String texts = "test";
    try {
        int intValue = Integer.valueOf(texts);
        System.out.println("is number");
    } catch(NumberFormatException ex) {
        System.out.println("is not a number");
    }
Kenny Tai Huynh
  • 1,464
  • 2
  • 11
  • 23