import java.util.Scanner; public class ArmstrongMethod { void Amg(int n) { 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"); } public static void main(String[] args) { AmstrongMethod obj = new AmstrongMethod(); Scanner scan = new Scanner(System.in); System.out.println("\nEnter a Number: "); int n = scan.nextInt(); obj.Amg(n); } } OUTPUT: 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 Method
Subscribe to:
Post Comments (Atom)
What programming language did you use on this program please?
ReplyDelete