Computer Science, asked by Rainbowgain, 22 days ago

Write a program to find Armstrong number in java ​

Answers

Answered by Anonymous
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, 22 days ago