[HELP] How to check an argument is a integer?

Discussion in 'Plugin Development' started by Steffion, Jul 15, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    Steffion

    The title says it.
    I tried this: but it didn't work... please help!
    Code:
    int hunger = new Int(args[2]);
     
  2. input.matches("[-]?[0-9]*")

    ^^ writen from my head, and I am not realy good whit those regulier expressions so high chace there is an small error inside
     
    Steffion likes this.
  3. Offline

    kSafin

    Just do

    Code:
    try {
      hunger = Integer.parseInt(args[2]);
    } catch (NumberFormatException e) {
      // Code for Invalid Input
    }
    Some say this is an invalid use of trycatch blocks, but it's actually completely OK to use TryCatch blocks to determine and or filter data in this fashion. That's not to give you the impression of just stuffing all of your data analysis into a try catch block.
     
    Steffion likes this.
  4. Offline

    Steffion

Thread Status:
Not open for further replies.

Share This Page