- 1

How to check whether the entered input is string or integer or float in java ?

1st Mar 2017, 1:17 PM
vikram gupta
vikram gupta - avatar
2 Antworten
+ 2
you can use this code int no=0; try { no=Integer.parseInt(string); if(string.contains(".")) { if(string.contains("f")) { System.out.println("float"); } else System.out.println("double"); } } catch(Exception ex) { Console.WriteLine("not numeric or string"); }
1st Mar 2017, 1:46 PM
Faruque Hossain
Faruque Hossain  - avatar
+ 2
You can check if the entered text is a number using regular exceptions. Or you simply try to convert it to number and it is a number of conversion was OK: try { int number = Integer.parseInt(input); // number } catch (NumberFormatException e) { // not a number }
1st Mar 2017, 8:05 PM
Tamás Barta
Tamás Barta - avatar