Wednesday, 4 November 2020

Armstrong number

 For example: 153 = 1*1*1 + 5*5*5 + 3*3*3 // 153 is an Armstrong number.


import java.util.Scanner;

public class Armstrong_Tridib

{

   public static void main(String[] args) 

    {

        Scanner br=new Scanner(System.in);

        System.out.println("Enter number of students");

        int n=br.nextInt();

        int number, temp, total = 0;

        number = n;

        while (number != 0)

        {

            temp = number % 10;

            total = total + temp*temp*temp;

            number /= 10;

        }

        if(total == n)

            System.out.println(n + " is an Armstrong number");

        else

            System.out.println(n + " is not an Armstrong number");

    }

}

No comments:

Post a Comment