Java - Check if input is a positive integer, negative integer, natural number and so on.

后端 未结 6 1116
长情又很酷
长情又很酷 2020-12-29 20:53

Is there any in-built method in Java where you can find the user input\'s type whether it is positive, or negative and so on? The code below doesn\'t work. I am trying to fi

6条回答
  •  天涯浪人
    2020-12-29 21:40

    For integers you can use Integer.signum()

    Returns the signum function of the specified int value. (The return value is -1 if the specified value is negative; 0 if the specified value is zero; and 1 if the specified value is positive.)

提交回复
热议问题