import java.util.*;
public class Ch2Q27
{
public static void main(String[] args)
{Scanner kbd = new Scanner(System.in);
System.out.print("Enter an integer: ");
int n = kbd.nextInt();
for(int no = 1; no < n; no++)
if(armstrong(no))
System.out.println(no);
}
static boolean armstrong(int no)
{int no1 = no, sum = 0;
while(no != 0)
{ int dig = no % 10;
no /= 10;
sum += Math.pow(dig, 3);
}
if(sum == no1)return true;
return false;
}
}
No comments:
Post a Comment