We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 230f04f commit f5754d3Copy full SHA for f5754d3
1 file changed
src/main/java/com/conversions/BinaryToGray.java
@@ -10,19 +10,19 @@ public class BinaryToGray
10
public String binaryToGray(String binarycode)
11
{
12
13
- String graycode = Character.toString(binarycode.charAt(0));
+ StringBuilder graycode = new StringBuilder(Character.toString(binarycode.charAt(0)));
14
15
for(int i = 0; i < binarycode.length() - 1; i++)
16
17
18
if (binarycode.charAt(i) == binarycode.charAt(i+1))
19
- graycode = graycode + "0";
+ graycode.append("0");
20
else
21
- graycode = graycode + "1";
+ graycode.append("1");
22
23
}
24
25
- return graycode;
+ return graycode.toString();
26
27
28
0 commit comments