Computer Science, asked by shreyanshitkinpeepnw, 1 year ago

Write a Program in bluej to check whether the number is Armstrong number or not.

Answers

Answered by Vk73829301
0
public class Armstrong { public static void main(String[] args) { int number = 1634, originalNumber, remainder, result = 0, n = 0; originalNumber = number; for (;originalNumber != 0; originalNumber /= 10, ++n); originalNumber = number; for (;originalNumber != 0; originalNumber /= 10) { remainder = originalNumber % 10; result += Math.pow(remainder, n); } if(result == number) System.out.println(number + " is an Armstrong number."); else System.out.println(number + " is not an Armstrong number."); } }
Answered by lenovoideapadanishka
2

import java.util.*;

class armstrong  

{

public static void main(String args[])

{

Scanner sc=new Scanner(System.in);

int s=0,d,di;

System.out.println("enter a no.");

int n=sc.nextInt();

int x=n;

while(x!=0)

{

d=x%10;

di=d*d*d;

s=s+di;

x=x/10;

}

if(s==n)

System.out.println("armstrong");

else

System.out.println("not armstrong");

}

}

Hope it helps!!!^_^

please mark me as the brainliest!!!!!

Similar questions