You are viewing a single comment's thread. Return to all comments →
The output is equals to the expected result but HackerRank states that it is wrong. :(
Compiler Message Wrong Answer Input (stdin) 02-08-2025 04-09-2025 Your Output (stdout) 5 Expected Output 5
Here is my Java code:
public static void main (String[] args) throws java.lang.Exception { Scanner in = new Scanner(System.in); String s = in.nextLine(); StringTokenizer str = new StringTokenizer(s, " "); String d1 = str.nextToken().trim(); String d2 = str.nextToken().trim(); SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy"); Date firstDate = formatter.parse(d1); Date secondDate = formatter.parse(d2); int result = 0; Calendar c = Calendar.getInstance(); SimpleDateFormat formatterLeadingZeroes = new SimpleDateFormat("dMMyyyy"); while (true) { int value = Integer.parseInt(formatterLeadingZeroes.format(firstDate)); if (value % 4 == 0 || value % 7 == 0) { result++; } c.setTime(firstDate); c.add(Calendar.DATE, 1); firstDate = c.getTime(); if (firstDate.after(secondDate)) { break; } } System.out.println(result); in.close(); }
Seems like cookies are disabled on this browser, please enable them to open this website
Prime Dates
You are viewing a single comment's thread. Return to all comments →
The output is equals to the expected result but HackerRank states that it is wrong. :(
Compiler Message Wrong Answer Input (stdin) 02-08-2025 04-09-2025 Your Output (stdout) 5 Expected Output 5
Here is my Java code: