From 47c44aacffe43e558b141b03a84897cdf9066974 Mon Sep 17 00:00:00 2001 From: Mani Manasa Mylavarapu Date: Sat, 21 Oct 2017 18:40:01 +0530 Subject: [PATCH 1/4] Added Armstrong number algorithm. fixes #96 --- Others/Armstrong.java | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Others/Armstrong.java diff --git a/Others/Armstrong.java b/Others/Armstrong.java new file mode 100644 index 000000000000..7cbc05502938 --- /dev/null +++ b/Others/Armstrong.java @@ -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; + } + + } +} \ No newline at end of file From 364e27b5a0bafa564363ce9fb907a11a00d7bf14 Mon Sep 17 00:00:00 2001 From: Mani Manasa Mylavarapu Date: Sat, 21 Oct 2017 23:22:07 +0530 Subject: [PATCH 2/4] 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 --- Armstrong.java | 47 +++++++++++++++++++++++++++++++++++++++++++ Others/Armstrong.java | 27 ++++++++++++++++--------- 2 files changed, 65 insertions(+), 9 deletions(-) create mode 100644 Armstrong.java diff --git a/Armstrong.java b/Armstrong.java new file mode 100644 index 000000000000..9267d9eaf648 --- /dev/null +++ b/Armstrong.java @@ -0,0 +1,47 @@ +import java.util.Scanner; + +/** + * A utility to check if a given number is armstrong or not. Armstrong number is + * a number that is equal to the sum of cubes of its digits for example 0, 1, + * 153, 370, 371, 407 etc. For example 153 = 1^3 + 5^3 +3^3 + * + * @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"); + } + } + + /** + * Checks whether a given number is an armstrong number or not. Armstrong + * number is a number that is equal to the sum of cubes of its digits for + * example 0, 1, 153, 370, 371, 407 etc. + * + * @param number + * @return boolean + */ + 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; + } + + } +} \ No newline at end of file diff --git a/Others/Armstrong.java b/Others/Armstrong.java index 7cbc05502938..fe12e2fbdd67 100644 --- a/Others/Armstrong.java +++ b/Others/Armstrong.java @@ -1,10 +1,14 @@ package Others; import java.util.Scanner; + /** - * To check if a given number is armstrong or not. + * A utility to check if a given number is armstrong or not. Armstrong number is + * a number that is equal to the sum of cubes of its digits for example 0, 1, + * 153, 370, 371, 407 etc. For example 153 = 1^3 + 5^3 +3^3 + * * @author mani manasa mylavarapu - * + * */ public class Armstrong { public static void main(String[] args) { @@ -12,19 +16,24 @@ public static void main(String[] args) { System.out.println("please enter the number"); int n = scan.nextInt(); boolean isArmstrong = checkIfANumberIsAmstrongOrNot(n); - if(isArmstrong) - { + if (isArmstrong) { System.out.println("the number is armstrong"); - } - else - { + } else { System.out.println("the number is not armstrong"); } } + /** + * Checks whether a given number is an armstrong number or not. Armstrong + * number is a number that is equal to the sum of cubes of its digits for + * example 0, 1, 153, 370, 371, 407 etc. + * + * @param number + * @return boolean + */ public static boolean checkIfANumberIsAmstrongOrNot(int number) { - int remainder, sum = 0,temp=0; - temp=number; + int remainder, sum = 0, temp = 0; + temp = number; while (number > 0) { remainder = number % 10; sum = sum + (remainder * remainder * remainder); From 70fc31a540bcc55495fbc0566b453574306ab799 Mon Sep 17 00:00:00 2001 From: Mani Manasa Mylavarapu Date: Wed, 25 Oct 2017 19:35:42 +0530 Subject: [PATCH 3/4] removed package name --- Others/Armstrong.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/Others/Armstrong.java b/Others/Armstrong.java index fe12e2fbdd67..9267d9eaf648 100644 --- a/Others/Armstrong.java +++ b/Others/Armstrong.java @@ -1,5 +1,3 @@ -package Others; - import java.util.Scanner; /** From 6dd5a9ccc51b82cf58dabf17b7c01cbb78c476aa Mon Sep 17 00:00:00 2001 From: Mani Manasa Mylavarapu Date: Wed, 25 Oct 2017 19:39:45 +0530 Subject: [PATCH 4/4] missed removing the file in root folder --- Armstrong.java | 47 ----------------------------------------------- 1 file changed, 47 deletions(-) delete mode 100644 Armstrong.java diff --git a/Armstrong.java b/Armstrong.java deleted file mode 100644 index 9267d9eaf648..000000000000 --- a/Armstrong.java +++ /dev/null @@ -1,47 +0,0 @@ -import java.util.Scanner; - -/** - * A utility to check if a given number is armstrong or not. Armstrong number is - * a number that is equal to the sum of cubes of its digits for example 0, 1, - * 153, 370, 371, 407 etc. For example 153 = 1^3 + 5^3 +3^3 - * - * @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"); - } - } - - /** - * Checks whether a given number is an armstrong number or not. Armstrong - * number is a number that is equal to the sum of cubes of its digits for - * example 0, 1, 153, 370, 371, 407 etc. - * - * @param number - * @return boolean - */ - 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; - } - - } -} \ No newline at end of file