Armstrong Number-Java Program

package javaPrograms;

import java.util.Scanner;

public class ArmstrongNumber
{

public static void main(String a[])
{
Scanner sc=new Scanner(System.in);
System.out.println("enter no to verify Armstrong no.");
int n=sc.nextInt();
int originalNumber=n;
        int resultNumber = 0;
 
       while(n>0)
       {
      int r=n%10;
          n=n/10;
      resultNumber=resultNumber+r*r*r;
     
       }

      if(originalNumber==resultNumber)
       {
      System.out.println("No  is  Armstrong");
       }
 
      else
      {
      System.out.println("No  is not Armstrong");
      }
}
}

Output
-----------------------------------------------------------------------------------------------------------------------

enter no to verify armstrong no.
153
No  is  Armstrong

Post a Comment

1 Comments

Emoji
(y)
:)
:(
hihi
:-)
:D
=D
:-d
;(
;-(
@-)
:P
:o
:>)
(o)
:p
(p)
:-s
(m)
8-)
:-t
:-b
b-(
:-#
=p~
x-)
(k)