Skip to content

Commit

Permalink
Update a test case
Browse files Browse the repository at this point in the history
Negetive numbers are not valid.
  • Loading branch information
bhupenchn committed Aug 17, 2015
1 parent 5afa053 commit e61edd1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
7 changes: 6 additions & 1 deletion 10_Harshad_Number/Java/darubramha89/HarshadNumbers.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ public class HarshadNumbers {

public static boolean isHarshad(int input)
{
if(input%decimalSum(input) == 0)
if(input <= 0)
{
System.out.println(input+" is invalid, enter a non-negative/non-zero number");
return false;
}
if(input%decimalSum(input) == 0)
{
System.out.println(input+" is Harshad Number");
return true;
Expand Down
3 changes: 2 additions & 1 deletion 10_Harshad_Number/Java/darubramha89/HarshadNumbers_test.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public static void main(String[] args) {
HarshadNumbers.isHarshad(111);
HarshadNumbers.isHarshad(201);
HarshadNumbers.isHarshad(921341);

HarshadNumbers.isHarshad(-11);
/** Output
12 is Harshad Number
11 is not a Harshad Number
Expand All @@ -20,3 +20,4 @@ public static void main(String[] args) {
}

}

0 comments on commit e61edd1

Please sign in to comment.