Skip to content
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

Added armstrong number implementation in java and Readme for Armstrong #15

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
37 changes: 37 additions & 0 deletions Armstrong.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

import java.util.Scanner;

public class Armstrong {

public void checkForArmstrong(int n)
{
int n2=n;
int sum=0;
while(n>0)
{
int n1=n%10;
n1=n1*n1*n1;
sum+=n1;
n=n/10;
}

if(sum==n2)
{
System.out.println("Its an Armstrong number");
}
else
{
System.out.println("Not an Armstrong number");
}
}

public static void main(String args[])
{
Armstrong obj=new Armstrong();
System.out.println("Enter a number to be checked");
Scanner scan = new Scanner(System.in);
int n=scan.nextInt();
obj.checkForArmstrong(n);
}

}
11 changes: 11 additions & 0 deletions Armstrong.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
An Armstrong number is a number in which the actual number is equal to the sum of cubes of individual digits of the number:

Example:
153
1*1*1=1

5*5*5=125

3*3*3=27

1+125+27=153