Tuesday 17 July 2018

Validate Armstrong Number using java- Interview qus Selenium

Definition:  A number is armstrong if the sum of the cubes of digit of number is equal to the number.
ex- 407 = 4*4*4 + 0*0*0 + 7*7*7




import java.util.Scanner;
public class ArmstrongNum{
public static void main(String[] args){
Scanner in = new Scanner(System.in);
System.out.println("Enter a number which you want to check whether that is armstrong or not: ");
int n = in.nextInt();
int a = n, c=0, b=0;
while(a!=0){
c = a%10;
a = a/10;
b = b + c*c*c;
}
if(b==n){
System.out.println("Number:   "+n+" is an armstrong number.");
}else{
System.out.println("Number "+n+" is not an armstrong number.");
}
}
}
Output



Enter a number which you want to check whether that is armstrong or not:
407
Number: 407 is an armstrong number.
Want to get strong in JAVA? Checkout our Free Java Course in Tamil

No comments:

Post a Comment

All Time Popular Posts

Most Featured Post

API Status Codes with examples for QA-Testers

  🔺 LinkedIn: https://www.linkedin.com/in/sidharth-shukla-77b53145/ 🔺 Telegram Group:  https://t.me/+FTf_NPb--GQ2ODhl 🏮In API testing, it...