Skip to content

Commit

Permalink
Merge pull request #289 from coder-mayank22/master
Browse files Browse the repository at this point in the history
Improved documentation for armstrong.java #280
  • Loading branch information
AkhzarFarhan authored Oct 31, 2024
2 parents 8e733a0 + 09d7351 commit bf7181e
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions Java/armstrong.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,32 @@ public static void main(String[] args) {

//Helps to prevent altering the original value
Temp = Number;
/*
* The 'Times' variable is used to store the number of digits in the number,
* which can then be used to check for Armstrong Number
*/
while (Temp != 0) {
Times = Times + 1;
Temp = Temp / 10;
}
}

Temp = Number;

/*
* The 'Sum' is calculated by adding each digit of the number raised to a power
* equal to the number of digits in the number, i.e. the 'Times' value
*/
while( Temp > 0) {
Reminder = Temp %10;
Sum = Sum + Math.pow(Reminder, Times);
Temp = Temp /10;
}
}
System.out.format("\n Sum of entered number is = %.2f", Sum);

/*
* If the calculated value of 'Sum' is equal to the original number, then the number is
* Armstrong, otherwise it is not
*/
if (Sum == Number) {
System.out.format("\n% d is a Armstrong Number", Number);
}
Expand Down

0 comments on commit bf7181e

Please sign in to comment.