Computer Science, asked by sthuti3230, 5 hours ago

print all armstrong no. from 100 to 500 in java

Answers

Answered by lavanya3602
1

this program takes dynamic inputs so, that you can give numbers of your choice.

import java.util.Scanner;

public class ArmstrongBetweenTwoNumbers {

  public static void main(String args[]){

     int num1, num2;

     Scanner sc = new Scanner(System.in);

     System.out.println("Enter the first number ::");

     num1 = sc.nextInt();

     System.out.println("Enter the second number ::");

     num2 = sc.nextInt();

     for (int i = num1; i<num2; i++){

        int check, rem, sum = 0;

        check = i;

        while(check != 0) {

           rem = check % 10;

           sum = sum + (rem * rem * rem);

           check = check / 10;

        }

        if(sum == i){

           System.out.println(""+i+" is an Armstrong number.");

        }

     }

  }

}

Similar questions