write a Java Program to with bufferedreader to find whether a number is an Armstrong number or not
Answers
Hello Friend!
How are you today?
Well I'm here to answer your question.
So lets get started!
____________________________
Your question is:
Write a java program to with buffered reader to find whether a number is an armstrong number or not.
_____________________________
My answer is:
import java.util.Scanner;
JavaExample {
public static void main(String[] args) {
int num, number, temp, total = 0;
System.out.println("Ënter 3 Digit Number");
Scanner scanner = new Scanner(System.in);
num = scanner.nextInt();
scanner.close();
number = num;
for( ;number!=0;number /= 10)
{
temp = number % 10;
total = total + temp*temp*temp;
}
if(total == num)
System.out.println(num + " is an Armstrong number");
else
System.out.println(num + " is not an Armstrong number");
}
}
______________________________
Hope this helps you!
Have a good day.