Checking if a player has typed an Integer

Discussion in 'Plugin Development' started by grasshopperMatt123, Mar 11, 2014.

Thread Status:
Not open for further replies.
  1. Hello, how do I check if a player has typed an integer, thanks Matt
     
  2. Offline

    Heirteir

    grasshopperMatt123
    Code:java
    1. try{
    2. int hello = (Integer) Integer.parseInt(<String Message>);
    3. //Code if is a number area above parses
    4. //a String as an interger so "65" will return 65
    5. }catch(Exception e)
    6. {
    7. //Code if it isn't a number
    8. }


    Hope it helped
     
    grasshopperMatt123 likes this.
  3. Offline

    Arcoz

    PHP:
     try {
                  
    int n Integer.parseInt(string); // String could be args[0] or something
                  //Do your method
                  
    } catch (NumberFormatException e) {
                  
    //If the string (as mentioned before could be args[0]) has letters in it,
                  //which means that it can't be an integer since there is no numbers in integers.
                  //So if it isn't an int
                    
    }
    EDIT: Ninjaed D:
     
    grasshopperMatt123 likes this.
  4. Offline

    Heirteir

    Arcoz
    Sorry D: well atleast you got the Exception to catch i couldn't remember :p
     
Thread Status:
Not open for further replies.

Share This Page