Java Online Compiler
Example: Java Program to Check Armstrong Number or Not without using Math.pow() function
C
C++
C#
Java
Python
PHP
Main.java
STDIN
Run
// Java Program to Check Armstrong Number using Math.pow() function import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int x, y, z, rem, rem2 = 1, n = 0, m = 0; double r = 0.00; // x - To store the input number // y & z - To store the storage of original input number to check // rem & rem2 - To store the reminder // r - To store the result variable System.out.println("-----Enter the integer number-----"); x = in.nextInt(); z = y = x; while (y != 0) { y /= 10; ++n; } m = n; while (z != 0) { rem = z % 10; rem2 = 1; while (n > 0) { rem2 *= rem; --n; } n = m; r += rem2; z /= 10; } // if x is equal to r, the number is an Armstrong number if ((int) r == x) { System.out.println("\n" + x + " is an Armstrong number."); } else { System.out.println("\n" + x + " is not an Armstrong number."); } } }
407
Output
Clear
ADVERTISEMENTS