Click here to Skip to main content
15,908,768 members
Please Sign up or sign in to vote.
1.33/5 (3 votes)
See more:
Enter a anumber
55 Number is not an ArmStrong.

What I have tried:

package com.streamapi;

import java.util.Scanner;

public class ArmStrongNumber {

	public static void main(String[] args) 
		Scanner scanner=new Scanner(;
		System.out.println("Enter a anumber");
		int number = scanner.nextInt();
		boolean ArmStrong = ArmStrong(number);

			System.out.println(number +" Number is an ArmStrong.");
			System.out.println(number +" Number is not an ArmStrong.");

	private static boolean ArmStrong(int number) {
		return false;
Updated 10-Mar-24 5:30am
Richard MacCutchan 10-Mar-24 8:55am    
What is the question?
Patrice T 10-Mar-24 9:11am    
And you have a problem or a question ?
PIEBALDconsult 10-Mar-24 11:29am    
We won't do your homework for you.

1 solution

You're almost there. All you have to do now is fill in the calculation part. That's a simple problem that shouldn't take you long. To help, I will remind you what the calculation is.

An Armstrong number is a number which is equal to the sum of each value raised to the power of the total number of digits. So, your calculation is going to take a string, and iterate over each character, converting it to a number, raising to the power of the string length. Add the value to the running total. If you reach the end of the loop and the total matches the input, congratulations, you found an Armstrong number.

There are some optimisations you can do. If the input isn't a number, reject it. If, during the loop, your running total exceeds the input value, it's definitely not an Armstrong number.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900