Datasets:

ArXiv:
License:
File size: 725 Bytes
c574d3a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import java.util.Scanner;  
import java.lang.Math;  
public class ArmstsrongNumber
{  
//function to check if the number is Armstrong or not  
static boolean isArmstrong(int n){   
	int m=n;
	int sum=0;
		while(m>0){
			int x=m%10;
			sum+=Math.pow(x,3);
			m/=10;
		}

		if(sum==n){
	   		return true;
		}else{
			return false;
		} 
}   
 
public static void main(String args[]){     
    int num;   
    Scanner sc= new Scanner(System.in);  
    System.out.print("Enter the limit: ");  
    //reads the limit from the user  
    num=sc.nextInt();  
    System.out.println("Armstrong Number up to "+ num + " are: ");  
    for(int i=0; i<=num; i++){       
	    if(isArmstrong(i)) System.out.print(i+ ", "); 
    }
}   
}