armstrong numbers problem java

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

showing results for - "armstrong numbers problem java"
Michela
05 Mar 2017
1// Java program to print all armstrong numbers between given range
2import java.util.Scanner;
3public class ArmstrongNumbersGivenRange 
4{
5   public static void main(String[] args) 
6   {
7      int number, startNumber, endNumber, a, rem, n, count = 0;
8      Scanner sc = new Scanner(System.in);
9      System.out.println("Please enter starting number range: ");
10      startNumber = sc.nextInt();
11      System.out.println("Please enter ending number range: ");
12      endNumber = sc.nextInt();
13      for(a = startNumber + 1; a < endNumber; a++)
14      {
15         n = a;
16         number = 0;
17         while(n != 0)
18         {
19            rem = n % 10;
20            number = number + rem * rem * rem;
21            n = n / 10;
22         }
23         if(a == number)
24         {
25            if(count == 0)
26            {
27               System.out.println("Armstrong numbers between given range " + startNumber + " and " + endNumber + ": ");
28            }
29            System.out.print(a + "  ");
30            count++;
31         }
32      }
33      // if there is no Armstrong number found between range
34      if(count == 0)
35      {
36         System.out.println("Sorry!! There's no armstrong number between given range " + startNumber + " and " + endNumber);
37      }
38      sc.close();
39   }
40}
Ayoub
25 Oct 2020
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}
Ella
17 Jul 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");   
Leonardo
05 Jan 2018
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 java codearmstrong no in javafind armstrong number in javawrite a java program that print the armstrong numberarmstrong number check in javacheck armstrong javato check whether a number is armstrong or not in javaa java program to accept an int from the user and check whether it is an arm strong number check for armstrong number in java4 digit armstrong number in javajava program for armstrong numberarmstrong in javacheck armstrong number javacode of armstrong numbers in javaarmstrong programming in javaarmstrong code in javaamstrong number javaarmstrong number in a given range in javajava program to find armstrong numberarm strong no in javalogic for armstrong number in javaallintitle 3aarmstrong number in javaprogram for armstrong number in javawrite a java program to check whether a number is armstrong or not using methods java program to print all armstrong numbers between given rangearmstrong no in javawrite a java program to check if the given number is an armstrong number or notjava program to print armstrong number from 1 to 1000armstrong no javaarmstrong number code in javaarmstrong number code javaarmstrong in range javahow to find a given no is armstrong in java15 check whether a given number is an armstrong number or not in javausing java generate armstrong no within range and display sum also printing the armstrong numbers between the given interval in javaarmstrong in javahow to check number is armstrong or not in javato check armstrong number in javaarmstrong number in java using command line argumentsarmstrong number logic in javaarmstrong number in java of 3 and 4 digitswrite a java program to find whether a given number is armstrong number or notamstrong number in javaarmstrong numbers in javacheck the number is armstrong or not in javaprint out all armstrong number in javajava program to check given number is armstrong or notarmstrong number in java programcheck whether the given number is armstrong or not javaamstrong 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 7darmstrong number checker in javaarmstrong numbers program javawrite a program to print all armstrong numbers in a given range in javajava code to check armstrong number4 digit armstrong number problem javacheck armstrong in javajava code for armstrong numberwap to check whether the number is an armstrong number or not in javaarmstrong or not in javaarmstrong number javaarmstrong number in java given rangearmstrong number in java with explanationjava program to print armstrong numbers between given rangearmstrong number logic program in javahow to find a string is armstrong or not in javaarmstrong of an number javajava program to check whether a given number is armstrong or notarmstrong number between given range in javaarmstring number code in javadefine armstrong number in javawrite a program in java to check armstrong numberprogram for armstrong numbers in javaarmstrong number code in havajava armstrong numberjava program to find armstrong numbersjava check if the given number is armstrong number or not check armstrong number in javaprinting the armstrong numbers between the given intervals in javaprint all armstrong numbers between two intervals javaarmstrong number in range javatest if armstrong number 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 5e3how to find an armstrong number in javadisplay all the armstrong number in a given range in javaarmstrong number or not in javaarmstrong number problem javaarmstrong program in javaarmstrong number in java for n digitswrite a java program to print armstrong number in a given interval rangecode for armstrong number in javahow to check if number is armstrong number in javahow to find armstrong number in javaarmstrong number using javajava armstrong number codeprogram to check if a number is armstrong or not in javafind armstrong number within a range javaarmstrong code javaarmstrong number in java stdin stdoutfind is number is armstrong or not in javacheck if a given number is an armstrong or not in java 8write a program to check given number is a armstrong number or not in javajava program armstrong numberhow to find the armstrong number in javaarmstrong number in java for 4 digitshow to find armstrong number of a stringarmstrong java program with two packagearmstrong number find in javaarmstrong number in java from m to n armstrong number in a given range injavacheck whether a given number is an armstrong number or not in javawrtie a program in java to check for an armstrong numberarmstrong number in java using for loopwhat is armstrong number in javasolving armstrong number javawrite a java program to check number is armstrong or notmultiset to check if number is armstrong javaarmstrong number find in java for 4 digitsarmstrong number in javacheck number is armstrong or not in javaarmstrong number program in javajava armstrong number algorithmarmstrong java programsalgorithm for armstrong number in javajava prgrm to find armstrong numberarmstrong number find in java for n digitsarmstrong numbers problem javaamstrong javacompute armsstrong number javajava program to check armstrong numberprogram of armstrong number in javaarmstrong no logic in javajava check if armstrong numberarmstrong number in java geeksforgeekscheck if a number is armstrong or not in javaprogram to check number is armstrong or not in javajava program to display armstrong numbers within a range javawhat is a armstrong number in javaarmstrong numbers problem java