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

Commit fad2577

Browse files
authored
Adding Support for big values
Can able to work with big numbers, without restrictions on the length of the inputs.
1 parent f6cb9ff commit fad2577

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

content/kata/LeapYears.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ Class LeapYearChecker{
4141

4242
while(inputLines.hasNext()){
4343
StringTokenizer tokens = new StringTokenizer(inputLines.next());
44-
int year = Integer.parseInt(tokens.nextToken());
45-
if(year<0){
44+
BigInteger year = new BigInteger(tokens.nextToken());
45+
if(year.compareTo(BigInteger.ZERO)==-1){
4646
reader.close();
4747
throw new Exception("Year cannot be negative");
4848
}
@@ -57,11 +57,11 @@ Class LeapYearChecker{
5757
reader.close();
5858
}
5959

60-
static boolean isLeapYear(int year){
61-
if(year%4!= 0){
60+
static boolean isLeapYear(BigInteger year){
61+
if(year.remainder(new BigInteger("4"))!= BigInteger.ZERO){
6262
return false;
6363
}
64-
else if(year % 100 == 0 && year%400!=0){
64+
else if(year.remainder(new BigInteger("100"))==BigInteger.ZERO && year.remainder(new BigInteger("400"))!=BigInteger.ZERO){
6565
return false;
6666
}
6767
return true;

0 commit comments

Comments
 (0)