1
Sep 14 '22
What's wrong?
1
u/AZYTHECAT Sep 14 '22
Hi, can you help me? My problem is how do i put more condition on my if else statement.
2
Sep 14 '22
Hey dude, use else if instead of else.
if (condition){}
else if(condition 2){}
else{}else is a last resort if non of the previous conditions are satisfied.
2
u/paridhi774 Sep 14 '22 edited Sep 14 '22
Just writing help on the title doesn't inform us what you need help with.
First before the try catch block, save the data in variables.
Then create another file
Name it as functions.java or something.
There create functions like
isValidAge()which returnsnullif valid or something like " Enter age between X and Y range" or instead you can just return boolen based on how you want to deal with it. You can also use inbuilt functions of you wanna do basic check of weather a value is all string or alpha numeric.Basically the point of this is that you will make the code cleaner and if you have to reuse it, it makes it easier.
Now this is all to check if the user input data is valid.
Then to handle the logic of what you wanna do with that data, u can use if else statement.