Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.javatechie.interview.programming;
- public class ArmstrongNumber {
- /**
- * 153 = 1*1*1 + 5*5*5 + 3*3*3 // 153 is an Armstrong number.
- **/
- public static boolean isArmstrongNumber(int no) {
- int temp = 0;
- int sum = 0;
- int original = no;
- while (no != 0) {
- temp = no % 10;
- sum = (int) (sum + Math.pow(temp, 3));
- no = no / 10;
- }
- return sum == original ? true : false;
- }
- public static void main(String[] args) {
- System.out.println(isArmstrongNumber(371));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement