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

Homework 3 completed #156

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
13 changes: 12 additions & 1 deletion src/main/java/core/basesyntax/BinaryString.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,17 @@ public class BinaryString {
* а возвращает String с представлением этого числа в двоичном виде.
*/
public String toBinaryString(int value) {
return null;
StringBuilder binaryResult = new StringBuilder();

Choose a reason for hiding this comment

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

let's remove this empty line, it's redundant

if (value == 0) {
return "0";
}

Choose a reason for hiding this comment

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

and here

for (int i = 0; value > 0; i++) {

Choose a reason for hiding this comment

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

this loop doesn't make a lot of sense, let's use while loop

binaryResult.append(((value % 2) == 0 ? "0" : "1"));

Choose a reason for hiding this comment

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

do we need ternary operator here?
what's gonna happen if we just remove it?

value /= 2;
}

return binaryResult.reverse().toString();
}
}