program to check Armstrong number in java

NIRAJ AHER

Founder of Java Engineering Programs. Follow me on Google+ ,Linked in.

You may also like...

2 Responses

  1. Sanjukta says:

    Another way to check if a number is an Armstrong number by taking user input..

    package com.practice.java;

    import java.util.Scanner;

    class Armstrong{
    public static void main(String args[]){
    System.out.println(“Enter a number”);

    Scanner sc = new Scanner(System.in);
    String a = sc.nextLine();
    int size = a.length();

    System.out.println(“Length of the input number is = ” + size);

    int num = Integer.parseInt(a);
    int n = num;
    int check=0,remainder;

    while(num > 0){
    remainder = num % 10;
    check = check + (int)Math.pow(remainder,size);
    num = num / 10;
    }
    if(check == n)
    System.out.println(n+” is an Armstrong Number”);
    else
    System.out.println(n+” is not an Armstrong Number”);

    sc.close();
    }
    }

Leave a Reply

Your email address will not be published. Required fields are marked *