-
-
Save pulsar256/9d0ea31a26a98791eca5e68ef4994877 to your computer and use it in GitHub Desktop.
3 bugs. Find them.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
import java.util.stream.Collectors; | |
public class FindMyBugs { | |
Byte[] buffer; | |
public FindMyBugs(byte[] buffer) { | |
this.buffer = buffer; | |
} | |
// calculate (simplified) checksum for all elements in buffer. | |
public int stupidChecksum() { | |
int sum = 0; | |
for(int i = 0; i <= buffer.length; sum += buffer[i], i++) | |
return sum; | |
} | |
// return all uneven elements in buffer | |
public List<Byte> getUneven() { | |
return Arrays.asList(buffer).stream().filter(b -> b % 3 == 0).collect(Collectors.toList()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
... and one bonus bug :)