Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.lang.Math;
- public class Armstrong500 {
- static int digits(int n)
- {
- int counter = 0;
- while(n > 0)
- {
- n = n / 10;
- counter++;
- }
- return counter;
- }
- static boolean check_Armstrong(int n)
- {
- int m = n, d, c = 0, no_digits = digits(n);
- while(n > 0)
- {
- d = n % 10;
- n = n / 10;
- c = c + (int)Math.pow(d, no_digits);
- }
- if(c == m)
- return true;
- else
- return false;
- }
- public static void main(String args[])
- {
- System.out.println("The Armstrong numbers between 1-500 are");
- for(int i = 1; i <= 2000; i++)
- {
- if(check_Armstrong(i))
- System.out.print(i + " ");
- }
- }
- }
Add Comment
Please, Sign In to add comment