Thursday, December 10, 2015

Java program to check ArmStrong Number


Java program to check ArmStrong Number:

package javaapplication1;
import java.util.*;

public class ArmStrongNumber {
    public static void main(String args[])
   {
      int n, sum = 0, og, r;

      Scanner in = new Scanner(System.in);
      System.out.println("Enter a number to check if it is an armstrong number");    
      n = in.nextInt();

      og = n;

      while( og != 0 )
      {
         r = og%10;
         sum = sum + r*r*r;
         og = og/10;
      }

      if ( n == sum )
         System.out.println("Entered number is an armstrong number.");
      else
         System.out.println("Entered number is not an armstrong number.");        
   }
}

Related Posts:

  • Java break statement: Java break statement: package javaapplication27; public class BreakDemo {     public static void main(String[] args) {     &nbs… Read More
  • String Length in java String Length in java: The length of the String is the actual number of character that contains in it.To get this value,call the length() method as … Read More
  • Overloading Constructor: Overloading Constructor: package overloadingconstrucror; public class Box {     double width;     double height;     d… Read More
  • Stack in java: Stack in java: package javaapplication27; import java.util.Stack; public class TestStack {         public static void main(Str… Read More
  • Increment And Decrement Operator Increment and Decrement Operator: package javaapplication16; public class IncrementAndDecrementOPeratorDemo {     public static void mai… Read More

0 comments:

Post a Comment