Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

Armstrong Number in Java

// program to print an Armstrong Number by taking user input.

public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int no = sc.nextInt();
        int t1 = no;
        int length = 0;
        while (t1 != 0) {
            length = length + 1;
            t1 = t1 / 10;

        }
        int t2 = no;
        int arm = 0;
        int rem;
        while (t2 != 0) {

            int mul = 1;
             rem = t2 % 10;
            for (int i = 1; i <= length; i++) {
                mul *= rem;
            }
            arm = arm + mul;
            t2 /= 10;
            if (arm == no) {
                System.out.println(no+ " Is an Armstrong Number !");
            } else {
                System.out.println("Non an Armstrong Number!");
            }


        }
    }
 
PREVIOUS NEXT
Tagged: #Armstrong #Number #Java
ADD COMMENT
Topic
Name
9+3 =