From f5754d3aefc5c1f7298addb17c02d64e9101d4a6 Mon Sep 17 00:00:00 2001 From: Nilanjan <48550673+nbdgit@users.noreply.github.com> Date: Fri, 3 May 2019 22:16:06 +0530 Subject: [PATCH] Add StringBuilder class --- src/main/java/com/conversions/BinaryToGray.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/conversions/BinaryToGray.java b/src/main/java/com/conversions/BinaryToGray.java index cf44b82e..1482b8d6 100644 --- a/src/main/java/com/conversions/BinaryToGray.java +++ b/src/main/java/com/conversions/BinaryToGray.java @@ -10,19 +10,19 @@ public class BinaryToGray public String binaryToGray(String binarycode) { - String graycode = Character.toString(binarycode.charAt(0)); + StringBuilder graycode = new StringBuilder(Character.toString(binarycode.charAt(0))); for(int i = 0; i < binarycode.length() - 1; i++) { if (binarycode.charAt(i) == binarycode.charAt(i+1)) - graycode = graycode + "0"; + graycode.append("0"); else - graycode = graycode + "1"; + graycode.append("1"); } - return graycode; + return graycode.toString(); } }