Skip to content

Added Armstrong number algorithm. #240

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions Others/Armstrong.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package Others;

import java.util.Scanner;
/**
* To check if a given number is armstrong or not.
* @author mani manasa mylavarapu
*
*/
public class Armstrong {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("please enter the number");
int n = scan.nextInt();
boolean isArmstrong = checkIfANumberIsAmstrongOrNot(n);
if(isArmstrong)
{
System.out.println("the number is armstrong");
}
else
{
System.out.println("the number is not armstrong");
}
}

public static boolean checkIfANumberIsAmstrongOrNot(int number) {
int remainder, sum = 0,temp=0;
temp=number;
while (number > 0) {
remainder = number % 10;
sum = sum + (remainder * remainder * remainder);
number = number / 10;
}
if (sum == temp) {
return true;
} else {
return false;
}

}
}