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

HW-2 #146

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

HW-2 #146

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
16 changes: 10 additions & 6 deletions src/main/java/core/basesyntax/BinaryString.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
package core.basesyntax;

public class BinaryString {

/**
* Напишите метод toBinaryString(), который принимает на вход целое число value,
* а возвращает String с представлением этого числа в двоичном виде.
*/
public String toBinaryString(int value) {
return null;
if (value == 0) {
return "0";
}

StringBuffer result = new StringBuffer();
Copy link
Contributor

Choose a reason for hiding this comment

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

read checklist attentively

Copy link
Author

Choose a reason for hiding this comment

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

Changed to StringBuilder. Will ask you tomorrow, why not StringBuffer or String.format() for example :)

Copy link
Contributor

Choose a reason for hiding this comment

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

while (value > 0) {
result.insert(0, value % 2);
value /= 2;
}
return result.toString();
}
}