From 1b9fcfa374925a8c72de58ba054b695da22d0c6e Mon Sep 17 00:00:00 2001 From: Daria Date: Mon, 27 Jul 2020 20:26:55 +0300 Subject: [PATCH 1/3] added solution --- src/main/java/core/basesyntax/BinaryString.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/core/basesyntax/BinaryString.java b/src/main/java/core/basesyntax/BinaryString.java index ebec6bf..e1a24c3 100644 --- a/src/main/java/core/basesyntax/BinaryString.java +++ b/src/main/java/core/basesyntax/BinaryString.java @@ -7,6 +7,6 @@ public class BinaryString { * а возвращает String с представлением этого числа в двоичном виде. */ public String toBinaryString(int value) { - return null; + return Integer.toBinaryString(value); } } From 786d751720a81918f77c04babdfd474ba745e5ae Mon Sep 17 00:00:00 2001 From: Daria Date: Mon, 27 Jul 2020 21:09:21 +0300 Subject: [PATCH 2/3] added solution --- src/main/java/core/basesyntax/BinaryString.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/core/basesyntax/BinaryString.java b/src/main/java/core/basesyntax/BinaryString.java index e1a24c3..6b5a62c 100644 --- a/src/main/java/core/basesyntax/BinaryString.java +++ b/src/main/java/core/basesyntax/BinaryString.java @@ -7,6 +7,16 @@ public class BinaryString { * а возвращает String с представлением этого числа в двоичном виде. */ public String toBinaryString(int value) { - return Integer.toBinaryString(value); + + StringBuilder valueToBinary = new StringBuilder(); + int decimal = value; + + while (decimal > 0) { + int remaining = decimal % 2; + valueToBinary.append(remaining); + decimal /= 2; + } + + return value == 0 ? String.valueOf(0) : valueToBinary.reverse().toString(); } } From 6bc13ba52a6eb251429fc4d1dfef3029ee6ed9a5 Mon Sep 17 00:00:00 2001 From: Daria Date: Tue, 28 Jul 2020 13:31:12 +0300 Subject: [PATCH 3/3] changes implemented --- src/main/java/core/basesyntax/BinaryString.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/core/basesyntax/BinaryString.java b/src/main/java/core/basesyntax/BinaryString.java index 6b5a62c..6b876e4 100644 --- a/src/main/java/core/basesyntax/BinaryString.java +++ b/src/main/java/core/basesyntax/BinaryString.java @@ -12,8 +12,7 @@ public String toBinaryString(int value) { int decimal = value; while (decimal > 0) { - int remaining = decimal % 2; - valueToBinary.append(remaining); + valueToBinary.append(decimal % 2); decimal /= 2; }