+ 1
Ned help please.
How can I make it possible so the UserA “ Input” doesn’t enter number below 18 ? Or it only enter 4 digits ex: 1994? https://code.sololearn.com/cm58Z8aYvrhC/?ref=app
9 Respuestas
+ 4
Then your code works fine except that you are Notifying about DOB input, after accepting. Instead add line 23 , before DOB input.
If you want to validate input as 4 digits, then you can check like if dob is between 1000 and 9999 (possible 4 digits).. But you can cut down to checking if age(UserA) is negative or above 100 then say "invalid input"
( edit: other way, Dob as String input, then find find it's length is 4 or not. if no, then invalid input. )
if( userA < 0 || userA > 100 )
System.out.println( "Invalid input ");
So this make 18 input is invalid for Year.
Hope its clears now..!
+ 2
What is the problem you are facing with this code? in terms of expected output with a sample input...!
+ 2
Be clear about your input. Do you accepting age or year of birth? If you take age as input, then directly use it.
Like
UserA = in.nextInt();
If you take input as year, then find age by current_year - input_year.
You are mixing these two.
+ 1
Yha yha i got !
0
Jayakrishna 🇮🇳 The problem is when ever i put a numer les than 18 its give me the output that is not supposed to. Basicaly i want it to only get 4 digits input like “ 1994 “ year of birth
0
Jayakrishna 🇮🇳 its a alchol shop , it cant sell alchol for under Age ! That is the concept
0
Jayakrishna 🇮🇳 How do i fix it ?
0
Year of birth is my input sir … Jayakrishna 🇮🇳