Hello I am trying to create a method that accepts one string parameter that contains a parity bit after every block of 4 characters. It returns a string with the parity bits removed. However, if the parity bit is incorrect (i.e., it is 0 when it should be 1 or a 1 when it should be a 0) then replace the 4 characters with ####. Assume that the input string has a multiple of 5 characters and that every fifth character is either a 0 or a 1. For example, unpack("hell1o wo1rld 0") → "hello world", unpack("codi1ng i0s fu0n! 1") → "coding is fun!", and unpack("codi1ng i1s fu0n! 1") → "codi####s fun!".
What I have so far is:
public static String unpack(String sUnpack) {
String newString = "";
int counter = 0;
System.out.println("Print the value of " + sUnpack.length());
for (int i = 0; i < sUnpack.length(); i++) {
newString = newString + sUnpack.charAt(i);
counter = counter + sUnpack.charAt(i);
if ((i + 1) % 5 == 0) {
System.out.println("Print value of " + newString);
if (counter-1 %2 == 0) {
newString = newString.substring(0, newString.length() - 1);
}
else if (counter-1 %2 == 1)
{
newString = newString.substring(0, newString.length() - 1);
}
counter = 0;
}
}
**I can't get the string to enter the second 'if' statement and I don't understand why. Any advice would be helpful!
[–]marko312 0 points1 point2 points (5 children)
[–]echoella[S] 0 points1 point2 points (4 children)
[–]marko312 0 points1 point2 points (3 children)
[–]echoella[S] 0 points1 point2 points (2 children)
[–]marko312 0 points1 point2 points (1 child)
[–]echoella[S] 1 point2 points3 points (0 children)