I am a programming enthusiast currently studying for App Development. We have started programming with Java for one months..Can someone help me fix this code?
• The user enters the date in the YYYYMMDD format
• Any impossible date is rejected:
– dates before Oct. 15th 1582 or after Dec, 31st, 2199
– impossible month (<1 or >12)
– impossible days (e.g. any day>31, a day>30 for some months, a day>28 in February of
a non-leap year, etc)
1st advice: Take the date input as a string.
With formatter and api:
Date date=new SimpleDateFormat("yyyyMMdd").parse(input);
Without formatter and api you can use String's substring method to parse an input string, for the year it would be:
Then for month:
And so on.
Scanner sc = new Scanner(System.in);
int date = sc.nextInt();
you have two isLeap() method at line 24 and 56
package is not supported by Sololearn
I need to complete the tests in IntelliJ-Project.
19991232 - correct
21010101 - correct
20030229 - correct
19800201 - correct
19190303 - correct
15821015 - correct
15821016 - test failed
21001231 - test failed
19291025 (black Friday) - test failed