Check armstrong number using command line arguments java

Let’s learn check armstrong number using command line arguments java.

Check armstrong number using command line arguments java

Let’s learn to write a program to check whether given number is armstrong number or not.

Also read – variables in java

Let’s execute below java program using command line arguments.

public class CommandLineArguments
{
   public static void main(String[] args)
   {
      int number = Integer.parseInt(args[0]);
      int input = number;
      int find = 0, remainder;
      while(number > 0)
      {
         remainder = number % 10;
         find = find + (int)Math.pow(remainder, 3);
         number = number / 10;
      }
      if(find == input)
      {
         System.out.println(input + " is an armstrong number.");
      }
      else
      {
         System.out.println(input + " is not a armstrong number.");
      }
   }
}


Output:

javac CommandLineArguments.java

java CommandLineArguments 153

153 is an armstrong number

java CommandLineArguments 568

568 is not an armstrong number.