Java Programming

Armstrong Number

Java programming example for check the given number is Armstrong number or not

8/26/2021
0 views
armstrong-number.javaJava
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
Armstrong NumberArmstrong TutorialJava tutorial

Loading comments...

Related Examples

Deliver breaking news, insightful commentary, and exclusive reports.

Targeting readers who rely on our platform to stay ahead of the curve.

Contact Us: benzingaheadlines@gmail.com