4 digit armstrong number in java

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

showing results for - "4 digit armstrong number in java"
Yasmina
28 Jan 2018
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}
Clotilde
26 Apr 2017
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}
Julian
09 May 2017
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");   
Alejandra
04 Aug 2020
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}
Isra
30 Aug 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
armstrong number in java from m to n armstrong number in java for 4 digitswhat is armstrong number in java 3 digitcheck for armstrong number in javaarmstrong number in java using for looparmstrong number in java w3schools functional approchhow to find the armstrong number in javaarmstrong numbers in javaarmstrong no in javaamstrong javamethod to check the number armstrong or not javaarmstrong number or not in javalogic for armstrong number in javaarmstrong or not in javaexample of armstrong number in javadisplay all the armstrong number in a given range in javaarmstrong number in java stdin stdoutarmstrong programming in javawhat is a armstrong number in javaprinting the armstrong numbers between the given intervals in javajava armstrong number codewap to check whether the number is an armstrong number or not in javawrite code for armstrong number javaarmstrong number in javafind is number is armstrong or not in java inbuilt functionshot to find armstrong number in javahow to find a string is armstrong or not in javahow to check number is armstrong or not in javaarmstrong number in java with explanationarmstrong no javacalculate armstrong number in javaarmstrong number concept in javacheck armstrong in javaarmstrong number of n digits in javaarmstrong number find in java for 4 digits armstrong number in javaarmstrong number in java for n digitscheck armstrong javaa java program to accept an int from the user and check whether it is an arm strong number armstrong in javato check whether a number is armstrong or not in javaprinting the armstrong numbers between the given interval in javajava program to find armstrong numbersarmstrong java program with two packagejava program to print all armstrong numbers between given rangearmstrong number find in javasolving armstrong number java4 digit armstrong number in javato write a java program to print whether the given number is armstrong numbers how to find armstrong number in javaamstrong number javacheck whether the given number is armstrong or not javaarmstrong no in javaarmstrong java programsfind armstrong number in javajava program armstrong numberto check armstrong number in javaprogram to check given number is armstrong or not in javawrite a java program to check whether a number is armstrong or not using methods armstrong number coding in javaarmstrong number check in javaarmstrong number code in havawhat is armstrong number in javahow to find a given no is armstrong in javaprogram for armstrong numbers in javawrtie a program in java to check for an armstrong numberjava armstrong number algorithmarmstrong number code javaarmstrong in javaarmstrong number in java using command line argumentsarmstrong number logic program in javawrite a program to check given number is a armstrong number or not in javawrite a java program that print the armstrong numberarmstrong code in javacheck the number is armstrong or not in 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 7dalgorithm for armstrong number in javajava program to check number is armstrong or notcheck armstrong number javaarmstrong number logic in javaarmstrong number in java of 3 and 4 digitsarmstrong number program in javaarmstrong number find in java for n digitsarmstrong program in javaarmstrong numbers problem java4 digit armstrong number problem javajava program to find armstrong numberarm strong no in javacheck whether the number is an armstrong number or not in javajava program to check whether a given number is armstrong or notneil armstrong number in javacheck armstrong number in javacheck whether a given number is an armstrong number or not in javahow to find armstrong number of a stringcompute armsstrong number javawrite a java program to check number is armstrong or notarmstrong numbers program javatest if armstrong number javaamstrong number in javaarmstrong number for n digits in javajava prgrm to find armstrong numberarmstrong number problem javaarmstrong number java codejava code to check armstrong numberarmstrong number code in javajava program to check given number is armstrong or notamstrong in javawrite a java program to check if the given number is an armstrong number or notmultiset to check if number is armstrong 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 5e3define armstrong number in javajava armstrong numberjava program for armstrong numberwap to check a given number is armstrong or not 3f javawrite a java program to find whether a given number is armstrong number or notjava check if armstrong numberjava program to check armstrong numberarmstrong number in java programarmstrong number java using for eachhow to find an armstrong number in javawrite a program in java to check armstrong numberarmstrong number using javaarmstrong string in javsarmstrong number in java given rangearmstrong number or not java programarmstrong number javaprogram for armstrong number in javaprint out all armstrong number in javacheck number is armstrong or not in javaarmstring number code in javaprogram to check number is armstrong or not in javaprogram of armstrong number in java15 check whether a given number is an armstrong number or not in javaarmstrong number in java geeksforgeeksto check whether the number is armstrong in javafind is number is armstrong or not in javaarmstrong of an number javaarmstrong number checker in javaarmstrong number check javacheck if a given number is an armstrong or not in java 8write a java program to find whether the given number is armstrong or notprogram to check if a number is armstrong or not in javajava code for armstrong numberjava check if the given number is armstrong number or not to print given number is armstrong number or not in javaarmstrong code javaarmstrong no logic in javaarmstrong number in a given range in javahow to find amstrong number in java armstrong number in java w3schoolscheck if a number is armstrong or not in javacode for armstrong number in javahow to check if number is armstrong number in javajava program to print armstrong numbers between given rangeallintitle 3aarmstrong number in javacode of armstrong numbers in java4 digit armstrong number in java