Friday, 11 December 2020

Armstrong number using Method

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

1 comment:

  1. What programming language did you use on this program please?

    ReplyDelete

If you have any doubts, please let me know

Pattern 31 & 32