Computer Science, asked by jbala4689ow6lnh, 1 year ago

Java program for Armstrong number

Answers

Answered by Dikshant7
0
This is a Java Program to Print Armstrong Number from 1 to 1000. Armstrong Number is an integer such that the sum of the cubes of its digits is equal to the number itself.

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) { System.out.print(i+" "); } sum = 0; } }}

Output:

$ javac Armstrong.java $ java Armstrong   Armstrong numbers from 1 to 1000:1 153 370 371 407

Answered by Sreyasree
4
public class p3
{
public static void armstrong(int n)
{
int n1 = n;
int n2 = 0;
int d;
while(n>0)
{
d = n%10;
n2 = n2+d*d*d;
n = n/10;
}
if (n2==n1)
System.out.println("Armstrong Number");
else
System.out.println(" Not Armstrong Number");
}
}

Sreyasree: plz mark it as brainliest
Sreyasree: please mark it as brainliest
Similar questions