4th Street Bar Hive-Bar

Hive-Bar Powered by Hive beta-fdb5b5b

Community post

AP Computer Science - The Armstrong Numbers

![APCSLogo.png](https://steemitimages.com/DQmXNmrb8ug59Z9Kck2Hq8wS9RJASeUFdrxruwWCNW8Fqri/APCSLogo.png)
An Armstrong number is defined to be an integer where the sum each digit raised to the power of the number of digits in the number equals the number itself. Haha. Sound confusing? Well here is are two examples:
![](https://steemitimages.com/DQmWvoUGX4LTX5c53fWZ4d2D63bGSXAbARuF7TDW96yUHZQ/image.png)
#### My program to find these numbers: Surprisingly this only took 53 lines of code... It can be done in less.
![Capture.PNG](https://steemitimages.com/DQmWiNHjLxNjviNViJUWeS3g6mTpwxM2XspAs5m9DfkZ7MF/Capture.PNG)
#### The output: Here are all Armstrong numbers from 1 to 100,000 1, 2, 3, 4, 5, 6, 7, 8, 9, 153, 370, 371, 407, 1634, 8208, 9474, 54748, 92727, 93084

If you want to try out the raw code yourself you can go to browxy.com or codiva.io and copy/paste this:

class Armstrong {
// This is the main class. It runs the program.
public static void main(String[] args) {
AllArmstrongNumbers(1,100000);
}
// This prints out all Armstrong numbers from 1st to 2nd argument.
public static void AllArmstrongNumbers(int min, int max) {
boolean ANum;
for (int i = min; i <= max; i++) {
ANum = isArmstrong(i);
if (ANum == true) {System.out.print(i + " ");}
}
}
// This counts the number of digits in a number.
public static int digitCount(int n) {
int count = 0;
while(n != 0) {
n = n / 10;
count++;
}
return count;
}
// This is an exponent calculator.
public static int power(int base, int exponent) {
int summ = base;
for(int i = 1; i < exponent; i++){
summ = summ*base;
}
return summ;
}
// This finds out if a number is Armstrong.
public static boolean isArmstrong(int num) {
int remainder;
int exp = digitCount(num);
int originalNumber = num;
boolean ArmstrongNumber;
int summ = 0;
for (int i = 1; i <= exp; i++) {
remainder = num % 10;
summ = summ + power(remainder,exp);
num = num / 10;
}
if (summ == originalNumber) {ArmstrongNumber = true;}
else {ArmstrongNumber = false;}
return ArmstrongNumber;
}
}

![BAR.png](https://steemitimages.com/DQmV1TfqJ7SzYtEtt6pxAAzFGDxT7qr96nBunRh8V5wiMPv/BAR.png)
#### All SteemitEducation Posts ###### Physics Kinematics Video, Circular Motion Video, Forces in 1 & 2 Dimensions Videos, Kinematics Full Lesson, Circular Motion and Gravitation Full Lesson, Kinematics and Forces Quiz, Forces in 1-Dimension, Forces in 2-Dimensions, Basic Physics, Kinematics, and Forces Review, AP Physics Midterm Exam, AP Physics Midterm Exam Solutions , Kinematics and Forces Quiz ###### Computer Science 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 ###### SAT Asymptotes, Composite Functions, Contest 1 - Area, Contest 1 – Winners and Solution, PEMDAS, Systems of Equations, Functions, Exponents, Contest 2 - More Functions, Contest 2 – Winners and Solution, Percents, The Interest Equation, All About Division, Contest 3 - Factoring, Contest 3 – Winners and Solution, Fractional and Negative Exponents, Basic Trig, Contest 4 - Math Vocab, Contest - 5, Contest 5 – Winners and Solution, Contest 6, Contest 6 – Winners and Solution ###### General Math Basics of Algebra, Trigonometry Video, Proof of Quadratic Formula, Factoring Video, Unions and Intersections, Surface Area of a Cylinder, Substitution Video, Combinatorics Basics ###### Graphing from Algebra to Calculus Algebra 1, Algebra 2, Pre-Calculus, Calculus ###### Piloting Airplanes Introduction, Preflight, Requirements, Instruments, Take-Offs and Landings, Why a Plane Can Fly, Reading the Runway, Maneuvers ###### Other Engineering (Isometric) Drawing, Pressure & SCUBA Diving
![BAR.png](https://steemitimages.com/DQmV1TfqJ7SzYtEtt6pxAAzFGDxT7qr96nBunRh8V5wiMPv/BAR.png)
Blessings to you Steemers! Learn much and teach your children!
![STMEdu.gif](https://steemitimages.com/DQmVM1RNSZQpF6FNR3FM19o1uxAsSPYQCM4rpKpVvHpAc7L/STMEdu.gif)
![LogoPicSteemit.png](https://steemitimages.com/DQmYAoBtivbBWrzDX4d5dnZ7t7eD7mMBRdJCGjBDCzcVpXH/LogoPicSteemit.png)
15 upvotes $0.50

Replies (23)

Review before signing

Posting as . Signing with . Keychain permission: Posting. Hive Keychain will ask you to approve this action next.


  
Technical details

Operation fingerprint: