We use the Modulo and division operation along with loops and if conditions to get the desired output.
Here is the source code of the Java Program to Print Armstrong Number from 1 to 1000. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.
public class Armstrong
public static void main(String args)
int n, count = 0, a, b, c, sum = 0;
System.out.print("Armstrong numbers from 1 to 1000:");
for(int i = 1; i <= 1000; i++)
n = i;
while(n > 0)
b = n % 10;
sum = sum + (b * b * b);
n = n / 10;
if(sum == i)
sum = 0;
$ javac Armstrong.java $ java Armstrong Armstrong numbers from 1 to 1000:1 153 370 371 407
Sanfoundry Global Education & Learning Series – 1000 Java Programs.