Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

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();														}}
Comment

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();														}}
Comment

PREVIOUS NEXT
Code Example
Java :: change activity main drawer items text color android 
Java :: priorityQueue peek java 
Java :: Add an element at a specified position in an ArrayList 
Java :: doubly linked list java add an element to the end 
Java :: define 2d array in java 
Java :: convert kotlin to java online 
Java :: java byte array to blob 
Java :: java hashtable 
Java :: varargs java 
Java :: java find largest number in list 
Java :: generic array creation java 
Java :: java android join array list 
Java :: sorting algorithms in java 
Java :: Java getClass() method 
Java :: finding min and max from given number in java 
Java :: java tamanho de um vetor 
Java :: remove java ubuntu 20.04 
Java :: 1.13. programacion orientada a objetos en java 
Java :: save text in edditext java 
Java :: matlab leslie eigenvalue java 
Sql :: conda install sqlalchemy 
Sql :: postgresql reset sequence 
Sql :: sql finding longest and shortest names in a fleld 
Sql :: oracle sql limit results 
Sql :: get tables in database sql 
Sql :: how to export database mysql terminal ubuntu 
Sql :: cast string to datetime mysql 
Sql :: postgresql add not null constraint 
Sql :: how to start mysql 
Sql :: select records for day before yesterday mysql 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =