Java program to find whether given no. is Armstrong or not

Share on FacebookTweet about this on TwitterDigg thisPin on PinterestShare on LinkedInShare on StumbleUponShare on TumblrShare on Google+Email this to someone
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/*Write a program to find whether given no. is Armstrong or not.
  Example :
  Input - 153
  Output - 1^3 + 5^3 + 3^3 = 153, so it is Armstrong no. */
class Armstrong{
	public static void main(String args[]){
		int num = Integer.parseInt(args[0]);
		int n = num; //use to check at last time
		int check=0,remainder;
		while(num > 0){
			remainder = num % 10;
			check = check + (int)Math.pow(remainder,3);
			num = num / 10;
		}
		if(check == n)
			System.out.println(n+" is an Armstrong Number");
		else
			System.out.println(n+" is not a Armstrong Number");
	}
}

Share on FacebookTweet about this on TwitterDigg thisPin on PinterestShare on LinkedInShare on StumbleUponShare on TumblrShare on Google+Email this to someone

10 Responses to “Java program to find whether given no. is Armstrong or not”

  1. iarap sana

    write a java program to create an array of 10 cells, store the values in the area at run time. find the largest and smallest element.

    Reply
  2. googzy

    Java program to find whether given no. is Armstrong or not using (if-else statement
    )

    Reply
  3. Lalit Addiwar

    Can I get the same program without using any functions?
    I need simple program without using any function as I am learning java now.

    Reply
  4. class armstrong
    {public static void accept(int no)
    {int p=no,rem,s=0;
    do
    {rem=p%10;
    s=s*10+rem;
    p=p/10;
    }
    while(p!=0);
    if(s==no)
    System.out.println(“it is an armstrong”);
    else
    System.out.println(“it is not an armstrong”);
    }}

    what is the error in it could anyone please reply

    Reply

Leave a Reply