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

updated Integers.java to use constants for readability #240

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
9 changes: 5 additions & 4 deletions src/com/jwetherell/algorithms/numbers/Integers.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ public static final boolean powerOfTwoUsingLoop(int numberToCheck) {
int number = numberToCheck;
if (number == 0)
return false;
while (number % 2 == 0) {
number /= 2;
while (number % TWO == 0) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed 2 --> two

number /= TWO;
}
if (number > 1)
return false;
Expand All @@ -78,9 +78,9 @@ public static final boolean powerOfTwoUsingRecursion(int numberToCheck) {
int number = numberToCheck;
if (number == 1)
return true;
if (number == 0 || number % 2 != 0)
if (number == 0 || number % TWO != 0)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 -->two

return false;
return powerOfTwoUsingRecursion(number / 2);
return powerOfTwoUsingRecursion(number / TWO);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2-->two

}

public static final boolean powerOfTwoUsingLog(int numberToCheck) {
Expand Down Expand Up @@ -142,6 +142,7 @@ public static final boolean powerOfTwoUsingBits(int numberToCheck) {
private static final int THOUSAND = 1000;
private static final int HUNDRED = 100;
private static final int TEN = 10;
private static final int TWO = 2; // New constant for 2

private static final String handleUnderOneThousand(int number) {
StringBuilder builder = new StringBuilder();
Expand Down