+ 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

23rd Apr 2023, 5:25 PM
Edson Macbey Mariano Mateus
Edson Macbey Mariano Mateus - avatar
8 Respostas
+ 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..!
23rd Apr 2023, 6:17 PM
Jayakrishna 🇼🇳
+ 2
What is the problem you are facing with this code? in terms of expected output with a sample input...!
23rd Apr 2023, 5:41 PM
Jayakrishna 🇼🇳
+ 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.
23rd Apr 2023, 5:57 PM
Jayakrishna 🇼🇳
+ 1
Yha yha i got !
23rd Apr 2023, 6:21 PM
Edson Macbey Mariano Mateus
Edson Macbey Mariano Mateus - avatar
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
23rd Apr 2023, 5:49 PM
Edson Macbey Mariano Mateus
Edson Macbey Mariano Mateus - avatar
0
Jayakrishna 🇼🇳 its a alchol shop , it cant sell alchol for under Age ! That is the concept
23rd Apr 2023, 5:51 PM
Edson Macbey Mariano Mateus
Edson Macbey Mariano Mateus - avatar
0
23rd Apr 2023, 6:00 PM
Edson Macbey Mariano Mateus
Edson Macbey Mariano Mateus - avatar
0
Year of birth is my input sir 
 Jayakrishna 🇼🇳
23rd Apr 2023, 6:03 PM
Edson Macbey Mariano Mateus
Edson Macbey Mariano Mateus - avatar