Thu Aug 26 2021
Armstrong Number
Java Programming1439 views
File Name: armstrong-number.java
import java.io.*;
class checking {
/* Constructor of the class */
checking(int number) {
int a = number, mod, ans = 0;
/* Loop the process using 'while' */
while(a != 0) {
mod = a % 10;
ans += (mod * mod * mod);
a = a / 10;
}
if(ans == number)
System.out.println("It's a Armstrong number");
else
System.out.println("It's not a Armstrong number");
}
}
class armstrong {
public static void main(String args[ ]) {
/* Create object of 'checking' class and pass value to it's constructor */
checking obj = new checking(Integer.parseInt(args[0]));
}
}
/* Output */
java armstrong 123
It's not a Armstrong number
/* ------------------------------ */
java armstrong 153
It's a Armstrong number
Reference:
Author:Geekboots