Computer Science, asked by karthikeyankarthik35, 1 month ago

write a JAVA program to INPUT a number and test if it is an AMSTRONG number​

Answers

Answered by ItzBrainlyQueen01
1

Explanation:

Programming :-

import java.util.Scanner;

import java.lang.Math;

public class ArmstsrongNumberExample2

{

static boolean isArmstrong(int n)

{

int temp, digits=0, last=0, sum=0;

temp = n;

while(temp>0)

{

temp = temp/10;

digits++;

}

temp = n;

while(temp>0)

{

last = temp % 10;

sum += (Math.pow(last, digits));

temp = temp/10;

}

if(n==sum)

return true;

else return false;

}

public static void main(String args[])

{

int num;

Scanner sc= new Scanner(System.in);

System.out.print("Enter the number: ");

num=sc.nextInt();

if(isArmstrong(num))

{

System.out.print("Armstrong ");

}

else

{

System.out.print("Not Armstrong ");

}

}

}

Output :-

  • Enter the number: 2

ㅤㅤArmstrong

  • Enter the number: 1675

ㅤNot Armstrong

Answered by dhruv13779
0

Answer:

this will help u bro

Explanation:

import java.util.*;

class amstrong_number

{

   public static void main(String args[])

   {

       Scanner sc=new Scanner(System.in);

       int num,sum=0,d,a,n=0,s=0;

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

       num=sc.nextInt();

       num=n;

       while(n>0)

       {

           a=n%10;

           s=s+a*a*a;

           n=n/10;

       }

       if(num==s)

       System.out.println("amstrong number");

       else

       System.out.println("not a amstrong number");

   }

}

Similar questions