Write a Java Program  to find Armstrong number

Write a Java Program to find Armstrong number

Write a Java Program to find Armstrong number

Program

import java.util.*;
public class Main 
{
    public static void main(String[] args) 
    {
        int n, arg, sum = 0, r;
        Scanner s=new Scanner(System.in);
        System.out.println("Enter a number: ");
        n=s.nextInt(); // input value
        arg = n; 
        for (int i = 1; i < n; i++) 
        {
            while (n > 0) 
            {
            r = n % 10; 
            sum = sum + (r * r * r);
            n = n / 10;
            }
        }
        if (arg == sum) 
        {
            System.out.println("Given number is armstrong number: " + arg);
        } 
        else 
        {
            System.out.println("Given number is not armstrong number: " + arg);
        }
    }
}




Output:

Enter a number: 153
Given number is armstrong number: 153



More Questions


31 . Write a Java Program to Calculate electricity bill
32 . Write a Java Program to find Armstrong number
33 . Write a java Program to print Armstrong number between 1 to 1000
34 . Write a java Program to Print given number in words
35 . Write a java Program to check the given number is Palindrome or not
36 . Write a java Program to print palindrome number upto N numbers
37 . Write a java Program to print N prime numbers and find sum and average
38 . Write a Java Program to find largest number in an array
39 . Write a Program to find second largest number in an array
40 . Write a Program to Find largest and smallest number in an array in java
41 . Write a Java Program to find largest and second largest in an array



For latest job updates join Telegram Channel: https://t.me/sateeshm

Apply For The Job

Apply For Job

Java Material

Python Material

PLSQL Material

.Net Material

Java Practice Programs

400 Java Programs