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

后端 未结 6 1084
长情又很酷
长情又很酷 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:43

    You could use if(number >= 0). The fact that you use int number = input.nextInt(); makes sure that it has to be an Integer.

提交回复
热议问题