Write a program to find Armstrong number in java
Answers
Answered by
73
Armstrong number:
➤ An Armstrong number is a number that is sum of the cubes of its digit, as
- 1³ + 5³ + 3³ = 153
- 3³ + 7³ + 0³ = 370
Program:
import java.util.*;
public class Armstrong {
public static void main(String[] args) {
Scanner sc=new Scanner (System.in);
long n=sc.nextInt(); //Enter a number
int c=0,s=0;long n1=n;
while (n!=0)
{
c++;
n/=10;
}
n=n1;
while (n1!=0)
{
s+=Math.pow(n1%10,c);
n1/=10;
}
if(s==n)
System.out.println("Armstrong");
System.out.println(3+7+""+7+6);
}
}
▬▬▬▬▬▬▬▬▬▬▬▬▬▬
Attachments:
Similar questions
Math,
11 days ago
Social Sciences,
11 days ago
Computer Science,
11 days ago
Economy,
22 days ago
Chemistry,
7 months ago
Math,
7 months ago