Untitled

mail@pastecode.io avatar
unknown
plain_text
5 months ago
1.0 kB
0
Indexable
public static void main(String[] args) {
        int ll, ul, n1 = 0, amstrong;
        Scanner s = new Scanner(System.in);
        System.out.println("enter lower limit");
        ll = s.nextInt();
        System.out.println("enter upper limit");
        ul = s.nextInt();
        for(int i=ll; i<=ul; i++){
           amstrong = ams(i); 
           if(amstrong == 0){
               continue;
           }
           else {
               System.out.println(amstrong);
           }
           
        }
        
    }

    public static int ams(int n) {
        int count = 0, a, x = 0,temp;
        temp = n;
        while (temp > 0) {
            count++;
            temp = temp / 10;           
        }
        temp = n;
        while (temp > 0) {
            a = temp%10;
            temp = temp / 10;      
            x = (int) (x + Math.pow(a, count));
        }
        if(x == n){
           return x;
        }
        else{
            return 0;
        }
        
        
        
    }
Leave a Comment