import java.util.*;
/* For example, 371 is an Armstrong number since 3**3 + 7**3 + 1**3 = 371.
* Write a program to find all Armstrong number in the range of 0 and 999.
*/
public class Armstrong {
public static void main(String[] args) {
int no=1,rem=1,mod=1,armstrong;
//check for armstrong
System.out.println("Enter armstrong no to be checked: ");
Scanner sc=new Scanner(System.in);
no=sc.nextInt();
armstrong=no;
while(no>=0)
{
System.out.println(no);
mod=no%10;
System.out.println(no);
rem=rem+(mod*mod*mod);
System.out.println(no);
no=no/10;
System.out.println(no);
}
if(no==armstrong)
System.out.println("it is armstrong no");
}
}
答案 0 :(得分:0)
避免无限循环。改变
while(no>=0)
到
while(no>0)
由于no=no/10;
可以将正数减少到0
。不低于此。
rem=0
,因为这是您计算总和的地方。