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