Write a Java program to print out all Armstrong numbers between 1 to 600 using loop


Introduction

In this demo I have used NetBeans IDE 8.2 for debugging purpose. But you can use any java programming language compiler as per your availability..


techstudy.org

Kindle Paperwhite High Resolution Display Tablet | Rs. 9999

  1. public class JavaLoopExcercise
  2. {
  3. public static void main(String[] args)
  4. {
  5. int digit1,
  6. digit2,
  7. digit3;
  8.  
  9. for(int number = 1; number <= 600; number++)
  10. {
  11. int temp = number;
  12. digit1 = temp % 10;
  13.  
  14. temp = temp / 10;
  15. digit2 = temp % 10;
  16.  
  17. temp = temp / 10;
  18. digit3 = temp % 10;
  19.  
  20. if(digit1*digit1*digit1 + digit2*digit2*digit2 + digit3*digit3*digit3 == number)
  21. {
  22. System.out.println(number);
  23. }
  24. }
  25. }
  26. }

Result

java techstudy.org

     





Related Topics


Responses




Popular Posts

Facebook

Founded in 2016, Tech Study passionately delivers stylish and dynamic innovative information to programmer and technology lovers. http://www.techstudy.org/.