+ 2

how to check if the input(with Scanner method) is number or alphabet in java

I need an example

21st Dec 2020, 11:15 AM
Jo$y ☑️
Jo$y ☑️ - avatar
5 Réponses
+ 4
To get integer input Use nextInt() method and for alphabet use next() method
21st Dec 2020, 11:39 AM
Piyush
Piyush - avatar
+ 2
You can use wrapper class character Character.isDigit(parameters) It will return true if input is a digit otherwise it will return false
21st Dec 2020, 1:33 PM
Piyush
Piyush - avatar
+ 1
What I want here is, if the user input an alphabet, to print "please use only numbers". If the user inputs a number, to execute a code.
21st Dec 2020, 1:25 PM
Jo$y ☑️
Jo$y ☑️ - avatar
+ 1
Thanks piyush 🏆
21st Dec 2020, 1:52 PM
Jo$y ☑️
Jo$y ☑️ - avatar
+ 1
Thank you Martin🎖️
21st Dec 2020, 1:52 PM
Jo$y ☑️
Jo$y ☑️ - avatar