-
Notifications
You must be signed in to change notification settings - Fork 129
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
base: master
Are you sure you want to change the base?
Homework 3 completed #156
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,17 @@ public class BinaryString { | |
* а возвращает String с представлением этого числа в двоичном виде. | ||
*/ | ||
public String toBinaryString(int value) { | ||
return null; | ||
StringBuilder binaryResult = new StringBuilder(); | ||
|
||
if (value == 0) { | ||
return "0"; | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. and here |
||
for (int i = 0; value > 0; i++) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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")); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we need ternary operator here? |
||
value /= 2; | ||
} | ||
|
||
return binaryResult.reverse().toString(); | ||
} | ||
} |
There was a problem hiding this comment.
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