Wednesday, December 2, 2020

To Find Amstrong Number Using JAVA Programming Language




Armstrong number is a number that is equal to the sum of cubes of its digits. The following program is to check your number is Armstrong or Not in  JAVA Programming Language


Armstrong number 
   
    
import java.util.Scanner;

public class ArmstrongNumber

{

	public static void main(String[] args)

	{

		int originalNumber, remainder, result = 0, n = 0;

		System.out.println("Enter the Number :");

		Scanner s = new Scanner(System.in);

		int number = s.nextInt();

		originalNumber = number;

		for (; originalNumber != 0; originalNumber /= 10, ++n);

		originalNumber = number;

		for (; originalNumber != 0; originalNumber /= 10)

		{

			remainder = originalNumber % 10;

			result += Math.pow(remainder, n);

		}

		if (result == number)

			System.out.println(number + " is an Armstrong number.");

		else

			System.out.println(number + " is not an Armstrong number.");

	}

}
    
    
    
  

Prime Number In Java Programming Language

Prime number  is a number that is greater than 1 and divided by 1 or itself only. In other words, prime numbers can't be divided by othe...