fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main(String[] args) {
  11. Scanner scanner = new Scanner(System.in);
  12. System.out.println("Enter the Range to Print Armstrong Number between Them");
  13. int start = scanner.nextInt();
  14. int end = scanner.nextInt();
  15. int counter = 0;
  16. for(int i = start; i < end; i++){
  17. int count = 0;
  18. int num = i;
  19. while(num!=0) { //Count no. of digits in the Number
  20. num /= 10;
  21. ++count;
  22. }
  23.  
  24. int temp = i;
  25. int cubeSum = 0;
  26. while(temp!=0) {
  27. int digit = temp % 10;
  28. cubeSum = cubeSum + (int)(Math.pow(digit , count));
  29. temp/=10;
  30. }
  31. if(cubeSum == i) {
  32. System.out.println(i + " is an Armstrong number ");
  33. if(counter == 0){
  34. System.out.println("Armstrong Number between " + start + " and " + end + ": ");
  35. }
  36. System.out.println(i + " ");
  37. counter++;
  38. }
  39. }
  40. if(counter == 0) {
  41. System.out.println("There is no Armstrong Number between " + start + " and " + end);
  42. }
  43.  
  44. }
  45. }
Success #stdin #stdout 0.23s 38356KB
stdin
100 10000
stdout
Enter the Range to Print Armstrong Number between Them
153 is an Armstrong number 
Armstrong Number between 100 and 10000: 
153  
370 is an Armstrong number 
370  
371 is an Armstrong number 
371  
407 is an Armstrong number 
407  
1634 is an Armstrong number 
1634  
8208 is an Armstrong number 
8208  
9474 is an Armstrong number 
9474