Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Armstrong.java #6130

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Patient-Pace-Coder
Copy link
Contributor

@Patient-Pace-Coder Patient-Pace-Coder commented Jan 12, 2025

Optimized Armstrong number check by removing string conversion
This update optimizes the Armstrong number check by eliminating the need for string conversion to calculate the number of digits. Instead, the number of digits is calculated using the Math.log10() function. This change improves both performance and readability, as we now compute the number of digits in a more efficient manner without converting the number to a string.

Changes made:
Removed string conversion (Integer.toString()) for calculating the number of digits.
Replaced it with a mathematical approach using Math.log10(num) + 1 to determine the number of digits in the given number.
The logic remains the same for summing each digit raised to the power of the number of digits.

  • I have read CONTRIBUTING.md.
  • This pull request is all my own work -- I have not plagiarized it.
  • All filenames are in PascalCase.
  • All functions and variable names follow Java naming conventions.
  • All new algorithms have a URL in their comments that points to Wikipedia or other similar explanations.
  • All new code is formatted with clang-format -i --style=file path/to/your/file.java

Optimized Armstrong number check by removing string conversion
@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 73.76%. Comparing base (bd785de) to head (d2ea630).

Additional details and impacted files
@@             Coverage Diff              @@
##             master    #6130      +/-   ##
============================================
- Coverage     73.77%   73.76%   -0.01%     
- Complexity     5120     5121       +1     
============================================
  Files           658      658              
  Lines         17619    17618       -1     
  Branches       3391     3391              
============================================
- Hits          12998    12996       -2     
- Misses         4117     4118       +1     
  Partials        504      504              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants