+ 5

How to print armstrong number for multiple digits....(for ex- 1634789)

in java

12th Feb 2018, 4:56 PM
ketana kasar
ketana kasar - avatar
4 Answers
+ 1
ans.... import java.math.*; import java.util.*; import java.lang.annotation.*; class Main { public static void main(String[] args) { int n,temp,digit=0,p; double r,sum=0; Scanner sc=new Scanner(System.in); n=sc.nextInt(); temp=n; while(temp!=0) { digit++; temp=temp/10; } temp=n; while(temp!=0) { r=temp%10; sum= sum+Math.pow(r,digit); temp=temp/10; } if(n==sum) System.out.println(n+ " armstronh no"); else System.out.println(n+ " not armstrong no"); } static int power(int n,int r) { int p=1; for(int c=1;c<=r;c++) p=p*n; return p; } }
14th Feb 2018, 2:24 AM
ketana kasar
ketana kasar - avatar
+ 1
https://code.sololearn.com/c1n4M4Gst2SZ/?ref=app
13th Feb 2018, 4:43 AM
Nashat
Nashat - avatar
+ 1
Nashat it's wrong answer bcoz only 3 digit allowed in program not proper ans.. for multiple digits.....
14th Feb 2018, 2:23 AM
ketana kasar
ketana kasar - avatar