Tuesday, January 29, 2019

Write a Java program to find whether given number is Armstrong or not
Armstrong numbers are: 153, 370, 371, 407
Definition: We call a given number as Armstrong if it is equal to the sum of the powers of its own digits.
Ex: abcd...n => pow(a,n) + pow(b,n) + pow(c,n) + pow(d,n) + .... =abcd...n
Answer:
package seleniumrepo;

import java.util.Scanner;
class ArmstrongNumber{
          public static void main(String args[]){
                int n, sum = 0, temp, r;
                Scanner in = new Scanner(System.in);
                System.out.println("Enter a number to check if it is an armstrong number");   
                n = in.nextInt();
                temp = n;
                while( n!= 0 ){
                       r = n%10;
                       sum = sum + r*r*r;
                       n= n/10;
                 }
                 if ( temp == sum )
                       System.out.println("Entered number is an armstrong number.");
                  else
                       System.out.println("Entered number is not an armstrong number."); 
   
                 in.close();
         }
}


Related Posts:

  • Selenium Example: How to verify whether the table column is sorted or not? Question: How do you check whether a table data(values) is sorted or not? Sorting happens when clicking on Table Header(Ex: Name, which is a link). Name Venu Avinash Dharma Answer: We c… Read More
  • Variables and Methods Variables: Variable is a name given to a memory location in which, we can store some value which can be used in a program. Variable Declaration: It is process of specifying what type of data to be stored into the memory … Read More
  • Data Types in Java Based on the type of data stored, data types are classifying as 3 types in Java. Primitive Datatype (Fundamental Datatype): Derived Datatype User Defined Datatype Primitive Datatype (Fundamental Datatype):  The da… Read More
  • Selenium Interview Questions and Answers I have attended some interviews during my career. I am sharing with you questions i was asked in the interviews. Hope these questions are helpful to the readers.    A Java Program to retrieve the data fro… Read More
  • Why Webdriver driver = new FirefoxDriver();        WebDriver driver =  new FirefoxDriver();                   (vs)        FirefoxDriver driver =  new Firef… Read More

0 comments:

Post a Comment

Selenium Training in Realtime

Blog helps to a student or IT employee to develop or improve skills in Software Testing.

Followers

About Me

My photo
Hyderabad, Andhra Pradesh, India
I am Automation Testing Professional. I have completed my graduation in B.Tech (Computers) from JNTU Hyderabad and started my career in Software Testing accidentally since then, I passionate on learning new technologies

Contact Form

Name

Email *

Message *

Popular Posts