We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
importjava.io.*;importjava.util.*;publicclassSolution{publicintcalculateFine(intd1,intm1,inty1,intd2,intm2,inty2){intfine=0;if(y1>y2){fine=10000;returnfine;}if((m1>m2)&&y1==y2){fine=500*(m1-m2);returnfine;}if((d1>d2)&&(m1==m2)&&(y2==y1)){fine=15*(d1-d2);returnfine;}if((d1<=d2)&&(m1==m2)&&(y2==y1)){fine=0;returnfine;}returnfine;}publicstaticvoidmain(String[]args){/* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */Scannersc=newScanner(System.in);//the first line contains 3 space separated integer denoting day, month and yearString[]date1=sc.nextLine().split(" ");intd1=Integer.parseInt(date1[0]);intm1=Integer.parseInt(date1[1]);inty1=Integer.parseInt(date1[2]);String[]date2=sc.nextLine().split(" ");intd2=Integer.parseInt(date2[0]);intm2=Integer.parseInt(date2[1]);inty2=Integer.parseInt(date2[2]);System.out.println(newSolution().calculateFine(d1,m1,y1,d2,m2,y2));}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Day 26: Nested Logic
You are viewing a single comment's thread. Return to all comments →
java