armstrong number in java

Solutions on MaxInterview for armstrong number in java by the best coders in the world

showing results for - "armstrong number in java"
Léandre
13 Mar 2017
1// Check whether a given number is armstrong number or not
2import java.util.Scanner;
3public class ArmstrongNumber
4{
5   public static void main(String[] args)
6   {
7      int x, y, z = 0, temp;
8      Scanner sc = new Scanner(System.in);
9      System.out.println("Please enter a number: ");
10      x = sc.nextInt();
11      temp = x;
12      while(x > 0)
13      {
14         y = x % 10;
15         x = x / 10;
16         z = z + (y * y * y);
17      }
18      if(temp == z)
19      {
20         System.out.println(temp + " is an Armstrong Number.");
21      }
22      else
23      {
24         System.out.println(temp + " is not an Armstrong Number.");
25      }
26      sc.close();
27   }
28}
Niklas
11 Oct 2018
1// 4 digit armstrong number in java
2public class ArmstrongNumberDemo
3{
4   public static void main(String[] args) 
5   {
6      int num = 9474, realNumber, remainder, output = 0, a = 0;
7      realNumber = num;
8      for(;realNumber != 0; realNumber /= 10, ++a);
9      realNumber = num;
10      for(;realNumber != 0; realNumber /= 10)
11      {
12         remainder = realNumber % 10;
13         output += Math.pow(remainder, a);
14      }
15      if(output == num)
16      {
17         System.out.println(num + " is an Armstrong number.");
18      }
19      else
20      {
21         System.out.println(num + " is not an Armstrong number.");
22      }
23   }
24}
Eoghan
21 Sep 2019
1 int c=0,a,temp;  
2    int n=153;//It is the number to check armstrong  
3    temp=n;  
4    while(n>0)  
5    {  
6    a=n%10;  
7    n=n/10;  
8    c=c+(a*a*a);  
9    }  
10    if(temp==c)  
11    System.out.println("armstrong number");   
12    else  
13        System.out.println("Not armstrong number");   
Jackie
11 Jul 2018
1import java.util.Scanner;
2
3public class Armstrong
4{
5  public static void main(String args[])
6  {
7    int num,temp,c=0;
8  	Scanner in=new Scanner(System.in);
9  	num=in.nextInt();
10  	temp=num;
11  	while(num!=0)
12  	{
13    	int d=num%10; //extracting last digit
14    	c+=d*d*d;
15    	num/=10; // removing last digit
16  	}
17  	if(temp==c)
18  	{
19    	System.out.println("Number is Armstrong");
20  	}
21  	else
22  		System.out.println("Number is not Armstrong");
23  }
24}
Claudio
08 May 2016
1import java.util.Scanner;
2
3/*
4 *@author: Mayank Manoj Raicha
5 * Armstrong Number in Java: A positive number is called armstrong number if it is equal to the sum of cubes of its digits 
6 * for example 0, 1, 153, 370, 371, 407 etc.
7 * 153 = (1*1*1)+(5*5*5)+(3*3*3)  = 1+125+27 = 153
8 */
9public class ArmstrongNumberExample {
10
11	public static void main(String[] args) {
12		
13		int sum = 0;
14		
15		Scanner in = new Scanner(System.in);
16		System.out.println("Enter the number: ");
17		int input = in.nextInt(); //1634
18		String val = String.valueOf(input);
19		char[] charArray = val.toCharArray();  //charArray[0] = "1" , charArray[1] = "6", charArray[2] = "3", charArray[3] = "4"
20		int[] numArray = new int[charArray.length]; //Declaring this array to store the result of getPowerOfNumber() method for each digit.
21		
22		//for each char element calculate the power of number and store it in the "cubedNumArray" array.
23		for(int i=0; i<charArray.length; i++) {
24			numArray[i] = getPowerOfNumber(Integer.parseInt(String.valueOf(charArray[i])), charArray.length);
25			sum = sum + numArray[i];
26		}
27		
28      //Compare if the resulting sum is equal to the original input.
29		if(sum == input) {
30			System.out.println("Entered number is an Armstrong number.");
31		}else {
32			System.out.println("Entered number is NOT an Armstrong number.");
33		}
34		
35		in.close();
36	}
37
38  	//Calculate & Return the value of the first argument raised to the power of the second argument
39	public static int getPowerOfNumber(int num, int count) {
40		return (int) Math.pow(num, count);
41	}
42}
queries leading to this page
check if a number is armstrong or not in javaarmstrong number in java w3schools functional approchfind is number is armstrong or not in java inbuilt functionsjava program to check whether a given number is armstrong or nothow to find a given no is armstrong in javawhat is a armstrong number in javahow to check number is armstrong or not in javaarmstrong code javafind is number is armstrong or not in javawrite a java program to find whether a given number is armstrong number or not15 check whether a given number is an armstrong number or not in javajava program for armstrong numberarmstrong number in java with explanationarmstrong number for n digits in javawrite a java program to check if the given number is an armstrong number or notcheck the number is armstrong or not in javawrtie a program in java to check for an armstrong numberarmstrong number in java of 3 and 4 digitscheck armstrong number javaarmstrong no in javacheck armstrong in javajava armstrong number codewrite a java program that print the armstrong numbercode of armstrong numbers in javawap to check whether the number is an armstrong number or not in javaarmstrong number problem javamultiset to check if number is armstrong javawrite a java program to check whether a number is armstrong or not using methods armstrong code in javaprint out all armstrong number in javacheck whether a given number is an armstrong number or not in javawrite a java program to check number is armstrong or notcheck for armstrong number in javaarmstrong number check in javaarmstrong in javaamstrong number in javaalgorithm for armstrong number in javadisplay all the armstrong number in a given range in javahow to find the armstrong number in javacheck if a given number is an armstrong or not in java 8java armstrong number algorithmarmstrong java programstest if armstrong number javaarmstrong number in java for 4 digitsarmstrong numbers program javawhat is armstrong number in javaarmstrong number check javaarmstrong number code in havahow to find armstrong number in javaarmstrong number code in javaarmstrong java program with two packagehow to find amstrong number in java to print given number is armstrong number or not in javaarmstrong programming in javaarmstrong numbers in javacheck armstrong javacheck whether the given number is armstrong or not javaamstrong number javato check armstrong number in javaarmstrong number find in java for n digitsarmstrong number using javacode for armstrong number in javaprogram of armstrong number in javajava program armstrong numbercheck number is armstrong or not in javaarmstrong no logic in javacheck armstrong number in javadefine armstrong number in javaprogram to check number is armstrong or not in javaarmstrong number concept in javajava program to check number is armstrong or notarmstrong number code javasolving armstrong number javaarmstrong number in javaarmstrong string in javsarmstrong number program in javaarm strong no in javaneil armstrong number in javawrite a java program to find whether the given number is armstrong or notjava check if the given number is armstrong number or not armstrong number coding in javaarmstrong number in java using command line argumentsarmstrong number checker in javaarmstrong program in javahow to check if number is armstrong number in javajava program to check given number is armstrong or notarmstrong in java4 digit armstrong number in javaarmstrong number java using for eachto check whether a number is armstrong or not in javawap to check a given number is armstrong or not 3f javaprinting the armstrong numbers between the given interval in javacheck whether the number is an armstrong number or not in javaarmstrong number in java geeksforgeeksarmstrong numbers problem javajava code for armstrong numberarmstrong number find in java for 4 digitsarmstrong no in javacompute armsstrong number javaarmstrong number in a given range in javahow to find an armstrong number in javaprogram to check if a number is armstrong or not in javaarmstrong number logic in javahow to find a string is armstrong or not in javafind armstrong number in javajava armstrong numberjava check if armstrong numberprogram to check given number is armstrong or not in javawrite code for armstrong number javajava program to find armstrong numberarmstrong of an number javajava code to check armstrong numberwrite a program in java to check armstrong numberjava program to find armstrong numbersallintitle 3aarmstrong number in javaa java program to accept an int from the user and check whether it is an arm strong number amstrong in javawrite a program to check if the given number is armstrong number or not for example 2c 153 is an armstrong number because of 153 3d 1 2b 125 2b27 2c which is equal to 1 5e3 2b5 5e3 2b3 5e3armstrong or not in javaarmstrong number in java for n digitsarmstring number code in javajava program to print all armstrong numbers between given rangejava program to check armstrong numberwrite a program to check given number is a armstrong number or not in javato write a java program to print whether the given number is armstrong numbers armstrong no javalogic for armstrong number in javaarmstrong number or not java program4 digit armstrong number problem javahot to find armstrong number in javawhat is armstrong number in java 3 digitamstrong javahow to find armstrong number of a stringarmstrong number in java stdin stdoutto check whether the number is armstrong in javaarmstrong number javaarmstrong number in java given rangearmstrong number logic program in javaarmstrong number of n digits in javamethod to check the number armstrong or not javaint c 3d0 2ca 2ctemp 3b int n 3d153 3b 2f 2fit is the number to check armstrong temp 3dn 3b while 28n 3e0 29 7b a 3dn 2510 3b n 3dn 2f10 3b c 3dc 2b 28a 2aa 2aa 29 3b 7d if 28temp 3d 3dc 29 system out println 28 22armstrong number 22 29 3b else system out println 28 22not armstrong number 22 29 3b 7dexample of armstrong number in javaarmstrong number in java using for loopprinting the armstrong numbers between the given intervals in javaarmstrong number in java from m to n armstrong number or not in javaarmstrong number in java w3schoolsjava prgrm to find armstrong numberjava program to print armstrong numbers between given rangeprogram for armstrong numbers in java armstrong number in javacalculate armstrong number in javaprogram for armstrong number in javaarmstrong number in java programarmstrong number find in javaarmstrong number java codearmstrong number in java