+ 5
How to print armstrong number for multiple digits....(for ex- 1634789)
in java
4 Respuestas
+ 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;
}
}
+ 1
https://code.sololearn.com/c1n4M4Gst2SZ/?ref=app
+ 1
Nashat it's wrong answer bcoz only 3 digit allowed in program not proper ans.. for multiple digits.....