Skip to content
This repository has been archived by the owner on May 20, 2020. It is now read-only.

Commit

Permalink
Adding Support for big values
Browse files Browse the repository at this point in the history
Can able to work with big numbers, without restrictions on the length of the inputs.
  • Loading branch information
jaydangar authored May 14, 2020
1 parent f6cb9ff commit fad2577
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions content/kata/LeapYears.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ Class LeapYearChecker{

while(inputLines.hasNext()){
StringTokenizer tokens = new StringTokenizer(inputLines.next());
int year = Integer.parseInt(tokens.nextToken());
if(year<0){
BigInteger year = new BigInteger(tokens.nextToken());
if(year.compareTo(BigInteger.ZERO)==-1){
reader.close();
throw new Exception("Year cannot be negative");
}
Expand All @@ -57,11 +57,11 @@ Class LeapYearChecker{
reader.close();
}

static boolean isLeapYear(int year){
if(year%4!= 0){
static boolean isLeapYear(BigInteger year){
if(year.remainder(new BigInteger("4"))!= BigInteger.ZERO){
return false;
}
else if(year % 100 == 0 && year%400!=0){
else if(year.remainder(new BigInteger("100"))==BigInteger.ZERO && year.remainder(new BigInteger("400"))!=BigInteger.ZERO){
return false;
}
return true;
Expand Down

1 comment on commit fad2577

@tclavier
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You really thinks we have the use case : I want to know if the year 2.147.483.648 is a leap year ? IMHO, no. Is it possible to have 2 solutions ?

Please sign in to comment.