![]() |
String to INT
I am trying to convert a string to int value. Is there anyway to implement a if else statement in this so if the user inputs anything else besides an int . it would display an error. otherwise if the user inputs a string of int's it displays the int's.
Code:
public static void main(String[] args) { |
Quote:
best regards |
pattern matching will help you to tell if it is a number, but still won't cast it so you'll still need the parse if you want to treat it as a number.
Just try/catch it instead, its much simpler. Integer.parseint will throw a NumberFormatException if it can't be parsed: PHP Code:
|
| All times are GMT +1. The time now is 09:44 PM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.