4 digit armstrong number in java

// Check whether a given number is armstrong number or not
import java.util.Scanner;
public class ArmstrongNumber
{
   public static void main(String[] args)
   {
      int x, y, z = 0, temp;
      Scanner sc = new Scanner(System.in);
      System.out.println("Please enter a number: ");
      x = sc.nextInt();
      temp = x;
      while(x > 0)
      {
         y = x % 10;
         x = x / 10;
         z = z + (y * y * y);
      }
      if(temp == z)
      {
         System.out.println(temp + " is an Armstrong Number.");
      }
      else
      {
         System.out.println(temp + " is not an Armstrong Number.");
      }
      sc.close();
   }
}

3.78
9
Starbuckns 105 points

                                    import java.util.Scanner;

/*
 *@author: Mayank Manoj Raicha
 * Armstrong Number in Java: A positive number is called armstrong number if it is equal to the sum of cubes of its digits 
 * for example 0, 1, 153, 370, 371, 407 etc.
 * 153 = (1*1*1)+(5*5*5)+(3*3*3)  = 1+125+27 = 153
 */
public class ArmstrongNumberExample {

	public static void main(String[] args) {
		
		int sum = 0;
		
		Scanner in = new Scanner(System.in);
		System.out.println("Enter the number: ");
		int input = in.nextInt(); //1634
		String val = String.valueOf(input);
		char[] charArray = val.toCharArray();  //charArray[0] = "1" , charArray[1] = "6", charArray[2] = "3", charArray[3] = "4"
		int[] numArray = new int[charArray.length]; //Declaring this array to store the result of getPowerOfNumber() method for each digit.
		
		//for each char element calculate the power of number and store it in the "cubedNumArray" array.
		for(int i=0; i<charArray.length; i++) {
			numArray[i] = getPowerOfNumber(Integer.parseInt(String.valueOf(charArray[i])), charArray.length);
			sum = sum + numArray[i];
		}
		
      //Compare if the resulting sum is equal to the original input.
		if(sum == input) {
			System.out.println("Entered number is an Armstrong number.");
		}else {
			System.out.println("Entered number is NOT an Armstrong number.");
		}
		
		in.close();
	}

  	//Calculate & Return the value of the first argument raised to the power of the second argument
	public static int getPowerOfNumber(int num, int count) {
		return (int) Math.pow(num, count);
	}
}

3.78 (9 Votes)
0
0
2
Nietaki 95 points

                                    import java.util.Scanner;

public class Armstrong
{
  public static void main(String args[])
  {
    int num,temp,c=0;
  	Scanner in=new Scanner(System.in);
  	num=in.nextInt();
  	temp=num;
  	while(num!=0)
  	{
    	int d=num%10; //extracting last digit
    	c+=d*d*d;
    	num/=10; // removing last digit
  	}
  	if(temp==c)
  	{
    	System.out.println("Number is Armstrong");
  	}
  	else
  		System.out.println("Number is not Armstrong");
  }
}

0
0
4.22
9
NiteCyper 95 points

                                    // 4 digit armstrong number in java
public class ArmstrongNumberDemo
{
   public static void main(String[] args) 
   {
      int num = 9474, realNumber, remainder, output = 0, a = 0;
      realNumber = num;
      for(;realNumber != 0; realNumber /= 10, ++a);
      realNumber = num;
      for(;realNumber != 0; realNumber /= 10)
      {
         remainder = realNumber % 10;
         output += Math.pow(remainder, a);
      }
      if(output == num)
      {
         System.out.println(num + " is an Armstrong number.");
      }
      else
      {
         System.out.println(num + " is not an Armstrong number.");
      }
   }
}

4.22 (9 Votes)
0
0
7
Mr Awesome8 100 points

                                     int c=0,a,temp;  
    int n=153;//It is the number to check armstrong  
    temp=n;  
    while(n>0)  
    {  
    a=n%10;  
    n=n/10;  
    c=c+(a*a*a);  
    }  
    if(temp==c)  
    System.out.println("armstrong number");   
    else  
        System.out.println("Not armstrong number");   

0
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
program for armstrong numbers in java write a java program to check number is armstrong or not java program armstrong number armstrong number in java given range how to find the armstrong number in java Write code for Armstrong Number. java write a program in java to check armstrong number Java program to print all armstrong numbers between given range how to find an armstrong number in java armstrong of an number java method to check the number armstrong or not java armstrong number in java with explanation ARMSTRONG NUMBER LOGIC PROGRAM IN JAVA to print given number is Armstrong number or not IN JAVA Printing the Armstrong numbers between the given interval in java Printing the Armstrong numbers between the given intervals in java armstrong number in java using for loop To check whether the number is Armstrong. in java Check whether the given number is Armstrong or not java armstrong no logic in java armstrong numbers problem java java program for armstrong number armstrong numbers in java java code for armstrong number display all the Armstrong number in a given range in Java armstrong number code in hava java program to find armstrong numbers armstrong numbers program java armstrong number in java for n digits armstrong number in java for 4 digits 4 digit ArmStrong number problem java ArmStrong number problem java to check armstrong number in java armstrong number concept in java armstrong no. in java allintitle:Armstrong number in java armstrong number in java neil armstrong number in java how to check number is armstrong or not in java find armstrong number in java program to check number is armstrong or not in java hot to find armstrong number in java armstrong number in java program 4 digit armstrong number in java armstrong number for n digits in java test if armstrong number java armstrong or not in java armstrong number in java stdin stdout armstrong number code in java how to find amstrong number in java armstrong string in javs check number is armstrong or not in java armstrong number in java w3schools functional approch armstrong number in java w3schools armstrong in java amstrong number java how to check if number is armstrong number in java WAP to check a given number is Armstrong or not? java java program to check number is armstrong or not algorithm for armstrong number in java program to check if a number is armstrong or not in java int c=0,a,temp; int n=153;//It is the number to check armstrong temp=n; while(n>0) { a=n%10; n=n/10; c=c+(a*a*a); } if(temp==c) System.out.println("armstrong number"); else System.out.println("Not armstrong number"); } armstrong number in java using command line arguments java armstrong number code armstrong number find in java for 4 digits armstrong number find in java for n digits armstrong number find in java Write a java program that print the Armstrong number armstrong programming in java how to find a given no is armstrong in java How to Find a String is armstrong or not in java How to find armstrong number of a string armstrong number java code armstrong number or not java program Write a Java program to find whether the given number is Armstrong or not armstrong number code java java check if armstrong number armstrong no java check whether the number is an armstrong number or not. in java armstring number code in java to check whether a number is armstrong or not in java what is a armstrong number in java armstrong number logic in java check armstrong number in java logic for armstrong number in java arm strong no in java find is number is armstrong or not in java inbuilt functions find is number is armstrong or not in java Write a java program to find whether a given number is armstrong number or not amstrong in java multiset to check if number is armstrong java compute armsstrong number java code for armstrong number in java check if a number is armstrong or not in java Check whether a given number is an Armstrong number or not in java armstrong no in java Define Armstrong Number in Java check the number is armstrong or not in java WAP to check whether the number is an Armstrong number or not in java what is armstrong number in java java program to check armstrong number java program to check whether a given number is armstrong or not check for armstrong number in java armstrong number in java of 3 and 4 digits armstrong number check in java java program to check given number is armstrong or not program to check given number is armstrong or not in java check armstrong java armstrong java program with two package armstrong java programs armstrong number java program for armstrong number in java armstrong program in java armstrong in java armstrong number of n digits in java java program to find armstrong number armstrong number using java a java program to accept an int from the user and check whether it is an arm-strong number. calculate armstrong number in java armstrong number java using for each armstrong number in java from m to n Write a Java Program to check if the given number is an Armstrong number or not Java check if the given number is Armstrong number or not. Write a program to check if the given number is Armstrong number or not. For example, 153 is an Armstrong number because of 153= 1+ 125+27, which is equal to 1^3+5^3+3^3 Write a program to Check given number is a armstrong number or not in Java code of armstrong numbers in java java prgrm to find armstrong number 15. Check whether a given number is an Armstrong number or not. in java Write a JAVA program to check whether a number is Armstrong or not using methods. armstrong code in java how to find armstrong number in java armstrong number checker in java armstrong number program in java check if a given number is an armstrong or not in java 8 amstrong number in java java armstrong number check armstrong number java java armstrong number algorithm amstrong java armstrong number in java
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source