Answers for "ARMSTRONG NUMBER LOGIC PROGRAM IN JAVA"

2

Armstrong number in java

// Check whether a given number is armstrong number or not
import java.util.Scanner;
public class ArmstrongNumber
{
   public static void main(String[] args)
   {
      int x, y, z = 0, temp;
      Scanner sc = new Scanner(System.in);
      System.out.println("Please enter a number: ");
      x = sc.nextInt();
      temp = x;
      while(x > 0)
      {
         y = x % 10;
         x = x / 10;
         z = z + (y * y * y);
      }
      if(temp == z)
      {
         System.out.println(temp + " is an Armstrong Number.");
      }
      else
      {
         System.out.println(temp + " is not an Armstrong Number.");
      }
      sc.close();
   }
}
Posted by: Guest on December-29-2020
3

4 digit armstrong number in java

// 4 digit armstrong number in java
public class ArmstrongNumberDemo
{
   public static void main(String[] args) 
   {
      int num = 9474, realNumber, remainder, output = 0, a = 0;
      realNumber = num;
      for(;realNumber != 0; realNumber /= 10, ++a);
      realNumber = num;
      for(;realNumber != 0; realNumber /= 10)
      {
         remainder = realNumber % 10;
         output += Math.pow(remainder, a);
      }
      if(output == num)
      {
         System.out.println(num + " is an Armstrong number.");
      }
      else
      {
         System.out.println(num + " is not an Armstrong number.");
      }
   }
}
Posted by: Guest on February-18-2021
2

armstrong number in java

int c=0,a,temp;  
    int n=153;//It is the number to check armstrong  
    temp=n;  
    while(n>0)  
    {  
    a=n%10;  
    n=n/10;  
    c=c+(a*a*a);  
    }  
    if(temp==c)  
    System.out.println("armstrong number");   
    else  
        System.out.println("Not armstrong number");
Posted by: Guest on March-11-2020

Code answers related to "ARMSTRONG NUMBER LOGIC PROGRAM IN JAVA"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language