Add StringBuilder class

This commit is contained in:
Nilanjan 2019-05-03 22:16:06 +05:30 committed by GitHub
parent 230f04f614
commit f5754d3aef
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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();
}
}