0
How to assure that the user 's input is a correct type of value?
for example,when i need input of others' ages,i need to assure that one enter a integer. i am wondering whether there is another way to do the same thing,distinguishing wrong values, as exception do. Thanks.
3 Antworten
+ 1
If you truly want to process your own inputs, you can code something like my getInput function in this code.
https://code.sololearn.com/cMMmkTfOxOoR/?ref=app
+ 1
Well you can define a method similarly to int.TryParse in c#.
something like
Boolean TryParse(string input){
try
{ Integer.parseInt(input);
return true;
}
catch{
return false;
}
}
and then
if(!TryParse(x)){
//some logic
}
I know that you have to use try catch, anyway it looks more elegant
+ 1
thanks,sir.sorry for thanking you so late