Computer Science, asked by srijansrivastav, 1 year ago

Write a program in java to check the number entered is a Armstrong number

Answers

Answered by Anonymous
3
hey mate ur answer is....
hope it help u...

plz mark me brainlist
✌✌✌
Attachments:
Answered by nitish8089
2

/*_____________________________________________________

Author:Nitish kumar jha

What's Armstrong number:

Armstrong number is a number that is equal to the sum

of cube of it's digits as:

Example=>

:::let's take a  number 153:::

where>>>

(1*1*1)=1:

(5*5*5)=125:

(3*3*3)=27:

so now let's add it:

1+125+27=153 as you see out it's equal to original number so this is an Armstrong number

______________________________________________________

/*

=====================================================

let's inform you about the input of this code so:::

1.  if you want to check(c) the no. is a Armstrong number 10000

just enter the input:::

===>c10000 or C10000;

==========((==========================(=====)))

2. if you want Armstrong number in a range then

(i) enter Range(r) in any case:

(ii) enter the ranging no. like 10000

------------input--------------

===>r10000 or R10000;

=====================================================

_______________________________________________________

:::now let's program:::*/

import java.io.*;

class Armstrong_number{

   public static void main(String...args) throws IOException{

       BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));

       String b=(reader.readLine());

       if(b.charAt(0)=='c'){

       int a=Integer.parseInt(b.substring(1,b.length()));

       int sum,temp;

       sum=0;

       temp=a;

       do{

           int x=temp%10;

           sum+=(x*x*x);

           temp/=10;

       }while(temp>0);

       if(sum==a)

       System.out.printf("%s %d %s","entered no :",a," is an armstrong number");

       else if(sum!=a)

       System.out.printf("%s %d %s","entered no :",a," is not an armstrong number");

   }

       else if(b.charAt(0)=='r'||b.charAt(0)=='R'){

       int d=Integer.parseInt(b.substring(1,b.length()));

       for(int i=1;i<=d;i++){int nsum,ntemp;

       nsum=0;

       ntemp=i;

       do{

           int x=ntemp%10;

           nsum+=(x*x*x);

           ntemp/=10;

       }while(ntemp>0);

       if(nsum==i)

       System.out.println(nsum);

   }

       }

   }

}


Similar questions