Answers for "amstrong"

0

amstrong

//Java program to check whether a number is armstrong or notimport java.util.Scanner;public class armstrong_number_or_not{	public static void main(String[] args)	{		//scanner class declaration		Scanner sc = new Scanner(System.in);		//input from user		System.out.print("Enter a number : ");						int number = sc.nextInt();		int n = number;		int sum = 0;		while(n != 0)		{			int pick_last = n % 10;			sum = sum + (pick_last * pick_last * pick_last);			n = n / 10;		}		//condition for checking that the sum is equal to the number or not			if(sum == number)			System.out.println("Armstrong Number");		else			System.out.println("Not an Armstrong Number");		//closing scanner class(not compulsory, but good practice)		sc.close();														}}
Posted by: Guest on June-10-2021
0

amstrong

//Java program to print armstrong numbers between two intervalsimport java.util.Scanner;public class armstrong_numbers_between_two_intervals{	public static void main(String[] args)	{		//scanner class declaration		Scanner sc = new Scanner(System.in);		//input from user		System.out.print("Enter Starting Number : ");		int start = sc.nextInt();		System.out.print("Enter Ending Number : ");		int end = sc.nextInt();		System.out.println("Armstrong numbers between "+start+" and "+end+" are : ");		int n, sum;		//loop for finding and printing all prime numbers between given range		for(int i = start ; i <= end ; i++)		{			n = i;			sum = 0;			//logic for checking number is armstrong or not			while(n != 0)			{				int pick_last = n % 10;				sum = sum + (pick_last * pick_last * pick_last);				n = n / 10;			}			if(sum == i)				System.out.println(i);		}		//closing scanner class(not compulsory, but good practice)		sc.close();														}}
Posted by: Guest on June-10-2021

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language