Get Adobe Flash player

Sunday, January 15, 2012

Armstrong number or not in Java

import java.io.*;

class Armstrong{
public static void main(String args[]){
try{
BufferedReader object = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter number");
int num= Integer.parseInt(object.readLine());
int n = num;
int check=0,remainder;
while(num > 0){
remainder = num % 10;
check = check + (int)Math.pow(remainder,3);
num = num / 10;
}
if(check == n)
System.out.println(n+" is an Armstrong Number");
else
System.out.println(n+" is not a Armstrong Number");
}
catch(Exception e){
System.out.println("Out of range!");
}
}
}


Example :



Input – 153

Output - 153 is Armstrong Number

1 comments:

ganga pragya said...

I likable the posts and offbeat format you've got here! I’d wish many thanks for sharing your expertise and also the time it took to post!!
DevOps Training in Bangalore

DevOps Training in Bangalore

DevOps Training in Bangalore

DevOps Training in Marathahalli

DevOps Training in Pune

DevOps Online Training-gangboard

Post a Comment