armstrong numbers problem java

// Java program to print all armstrong numbers between given range
import java.util.Scanner;
public class ArmstrongNumbersGivenRange 
{
   public static void main(String[] args) 
   {
      int number, startNumber, endNumber, a, rem, n, count = 0;
      Scanner sc = new Scanner(System.in);
      System.out.println("Please enter starting number range: ");
      startNumber = sc.nextInt();
      System.out.println("Please enter ending number range: ");
      endNumber = sc.nextInt();
      for(a = startNumber + 1; a < endNumber; a++)
      {
         n = a;
         number = 0;
         while(n != 0)
         {
            rem = n % 10;
            number = number + rem * rem * rem;
            n = n / 10;
         }
         if(a == number)
         {
            if(count == 0)
            {
               System.out.println("Armstrong numbers between given range " + startNumber + " and " + endNumber + ": ");
            }
            System.out.print(a + "  ");
            count++;
         }
      }
      // if there is no Armstrong number found between range
      if(count == 0)
      {
         System.out.println("Sorry!! There's no armstrong number between given range " + startNumber + " and " + endNumber);
      }
      sc.close();
   }
}

4
6
Krish 100200 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(&quot;Enter the number: &quot;);
		int input = in.nextInt(); //1634
		String val = String.valueOf(input);
		char[] charArray = val.toCharArray();  //charArray[0] = &quot;1&quot; , charArray[1] = &quot;6&quot;, charArray[2] = &quot;3&quot;, charArray[3] = &quot;4&quot;
		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 &quot;cubedNumArray&quot; array.
		for(int i=0; i&lt;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(&quot;Entered number is an Armstrong number.&quot;);
		}else {
			System.out.println(&quot;Entered number is NOT an Armstrong number.&quot;);
		}
		
		in.close();
	}

  	//Calculate &amp; 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);
	}
}

4 (6 Votes)
0
4.67
3
A-312 69370 points

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

4.67 (3 Votes)
0
3.86
8
Bippy 8155 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 + &quot; is an Armstrong number.&quot;);
      }
      else
      {
         System.out.println(num + &quot; is not an Armstrong number.&quot;);
      }
   }
}

3.86 (7 Votes)
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
Armstrong number in Java geeksforgeeks 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 a program in java to check armstrong number how to find an armstrong number in java armstrong of an number java armstrong number in java with explanation ARMSTRONG NUMBER LOGIC PROGRAM 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 Check whether the given number is Armstrong or not java armstrong no logic in java write a program to print all armstrong numbers in a given range in java print all armstrong numbers between two intervals java armstrong numbers problem java Find Armstrong number within a range java java program for armstrong number armstrong numbers in java write a java program to print armstrong number in a given interval range java code for armstrong number armstrong number between given range in java 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 no. in java armstrong number in range java java program to display armstrong numbers within a range java allintitle:Armstrong number in java Java program to print armstrong number from 1 to 1000 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 using Java Generate Armstrong no within range and display sum also Java program to print all armstrong numbers between given range armstrong number in java program 4 digit armstrong number in java test if armstrong number java armstrong or not in java armstrong number in java stdin stdout armstrong number code in java check number is armstrong or not in java armstrong in java amstrong number java how to check if number is armstrong number in java 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&gt;0) { a=n%10; n=n/10; c=c+(a*a*a); } if(temp==c) System.out.println(&quot;armstrong number&quot;); else System.out.println(&quot;Not armstrong number&quot;); } 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 code java java check if armstrong number armstrong no 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 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 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 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. 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