Skip to content

Commit 364e27b

Browse files
author
Mani Manasa Mylavarapu
committed
moved the class from others papckage to default.
and implemeted the following review comments. Remove the package Please provide a description for checkIfANumberIsAmstrongOrNot function Provide a description for what actually is an Armstrong number at the top along with an example fixes #96
1 parent 47c44aa commit 364e27b

File tree

2 files changed

+65
-9
lines changed

2 files changed

+65
-9
lines changed

Armstrong.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import java.util.Scanner;
2+
3+
/**
4+
* A utility to check if a given number is armstrong or not. Armstrong number is
5+
* a number that is equal to the sum of cubes of its digits for example 0, 1,
6+
* 153, 370, 371, 407 etc. For example 153 = 1^3 + 5^3 +3^3
7+
*
8+
* @author mani manasa mylavarapu
9+
*
10+
*/
11+
public class Armstrong {
12+
public static void main(String[] args) {
13+
Scanner scan = new Scanner(System.in);
14+
System.out.println("please enter the number");
15+
int n = scan.nextInt();
16+
boolean isArmstrong = checkIfANumberIsAmstrongOrNot(n);
17+
if (isArmstrong) {
18+
System.out.println("the number is armstrong");
19+
} else {
20+
System.out.println("the number is not armstrong");
21+
}
22+
}
23+
24+
/**
25+
* Checks whether a given number is an armstrong number or not. Armstrong
26+
* number is a number that is equal to the sum of cubes of its digits for
27+
* example 0, 1, 153, 370, 371, 407 etc.
28+
*
29+
* @param number
30+
* @return boolean
31+
*/
32+
public static boolean checkIfANumberIsAmstrongOrNot(int number) {
33+
int remainder, sum = 0, temp = 0;
34+
temp = number;
35+
while (number > 0) {
36+
remainder = number % 10;
37+
sum = sum + (remainder * remainder * remainder);
38+
number = number / 10;
39+
}
40+
if (sum == temp) {
41+
return true;
42+
} else {
43+
return false;
44+
}
45+
46+
}
47+
}

Others/Armstrong.java

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,39 @@
11
package Others;
22

33
import java.util.Scanner;
4+
45
/**
5-
* To check if a given number is armstrong or not.
6+
* A utility to check if a given number is armstrong or not. Armstrong number is
7+
* a number that is equal to the sum of cubes of its digits for example 0, 1,
8+
* 153, 370, 371, 407 etc. For example 153 = 1^3 + 5^3 +3^3
9+
*
610
* @author mani manasa mylavarapu
7-
*
11+
*
812
*/
913
public class Armstrong {
1014
public static void main(String[] args) {
1115
Scanner scan = new Scanner(System.in);
1216
System.out.println("please enter the number");
1317
int n = scan.nextInt();
1418
boolean isArmstrong = checkIfANumberIsAmstrongOrNot(n);
15-
if(isArmstrong)
16-
{
19+
if (isArmstrong) {
1720
System.out.println("the number is armstrong");
18-
}
19-
else
20-
{
21+
} else {
2122
System.out.println("the number is not armstrong");
2223
}
2324
}
2425

26+
/**
27+
* Checks whether a given number is an armstrong number or not. Armstrong
28+
* number is a number that is equal to the sum of cubes of its digits for
29+
* example 0, 1, 153, 370, 371, 407 etc.
30+
*
31+
* @param number
32+
* @return boolean
33+
*/
2534
public static boolean checkIfANumberIsAmstrongOrNot(int number) {
26-
int remainder, sum = 0,temp=0;
27-
temp=number;
35+
int remainder, sum = 0, temp = 0;
36+
temp = number;
2837
while (number > 0) {
2938
remainder = number % 10;
3039
sum = sum + (remainder * remainder * remainder);

0 commit comments

Comments
 (0)