Day 26: Nested Logic Hackerrank Solution Java
For Explanation Check Video:
Sample Input
STDIN Function
----- --------
9 6 2015 day = 9, month = 6, year = 2015 (date returned)
6 6 2015 day = 6, month = 6, year = 2015 (date due)
Sample Output
45
Code:
import java.io.*;import java.util.*;
public class Solution {
public static void main(String[] args) { Scanner scn = new Scanner(System.in); int actualDay = scn.nextInt(); int actualMonth = scn.nextInt(); int actualYear = scn.nextInt(); int exceptedDay = scn.nextInt(); int exceptedMonth = scn.nextInt(); int exceptedYear = scn.nextInt(); int fine; if(actualYear>exceptedYear){ fine = 10000; }else if(actualMonth>exceptedMonth &&actualYear==exceptedYear ){ fine = 500*(actualMonth-exceptedMonth); }else if(actualDay>exceptedDay && actualMonth==exceptedMonth && actualYear==exceptedYear){ fine = 15 * (actualDay-exceptedDay); }else{ fine = 0; } System.out.println(fine); }}
Comments
Post a Comment