Skip to content

Commit 230f04f

Browse files
havanagrawalnbdgit
andauthored
Apply suggestions from code review
Co-Authored-By: nbdgit <48550673+nbdgit@users.noreply.github.com>
1 parent 3b72294 commit 230f04f

2 files changed

Lines changed: 8 additions & 11 deletions

File tree

src/main/java/com/conversions/BinaryToGray.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,26 @@
33
public class BinaryToGray
44
{
55
/* This method convert the binary number into gray code
6-
@param binaryno need to convert binary number into gray code
6+
@param binarycode need to convert binary number into gray code
77
@return graycode return as string
88
*/
99

1010
public String binaryToGray(String binarycode)
1111
{
1212

13-
String graycode=Character.toString(binarycode.charAt(0));
14-
13+
String graycode = Character.toString(binarycode.charAt(0));
1514

16-
for(int i=0;i<binarycode.length()-1; i++)
15+
for(int i = 0; i < binarycode.length() - 1; i++)
1716
{
1817

19-
if(binarycode.charAt(i)==binarycode.charAt(i+1))
20-
graycode=graycode+"0";
18+
if (binarycode.charAt(i) == binarycode.charAt(i+1))
19+
graycode = graycode + "0";
2120
else
22-
graycode=graycode+"1";
21+
graycode = graycode + "1";
2322

2423
}
2524

2625
return graycode;
27-
2826
}
2927

3028
}

src/test/java/com/conversions/BinaryToGrayTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,11 @@
77
public class BinaryToGrayTest
88
{
99

10-
1110
@Test
1211
public void testBinaryToGray()
1312
{
14-
BinaryToGray btog=new BinaryToGray();
15-
assertEquals("1101",btog.binaryToGray("1001"));
13+
BinaryToGray btog = new BinaryToGray();
14+
assertEquals("1101", btog.binaryToGray("1001"));
1615
assertEquals("11010011101",btog.binaryToGray("10011101001"));
1716
}
1817

0 commit comments

Comments
 (0)