import java.util.*; public class Armstrong { public static void main(String[] args) { Scanner scan = new Scanner(System.in); System.out.println("\nEnter a Number: "); int n = scan.nextInt(); int reminder,amstrong=0,temp=n; while(n!=0) { reminder=n%10; amstrong=amstrong+reminder*reminder*reminder; n=n/10; } if(temp==amstrong) { System.out.println("\n"+temp+" is an amstrong number"); } else { System.out.println("\n"+temp+" is not an amstrong number"); } } } OUTPUT 1: Enter a Number: 591 591 is not an amstrong number OUTPUT 2: Enter a Number: 370 370 is an amstrong number
Basic Java programs. All programs done in very simple ways. It helps beginners to grow their programming skills and build a programming logic.
Friday, 11 December 2020
Armstrong number using while loop
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
If you have any doubts, please let me know