Guest User

Untitled

a guest
Jun 18th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.94 KB | None | 0 0
  1. public boolean impossible(byte[] myBytes) {
  2. if (myBytes.length == 0)
  3. return false;
  4. String string = new String(myBytes, "UTF-8");
  5. return string.length() == 0;
  6. }
  7.  
  8. public static void main(String[] args) throws UnsupportedEncodingException {
  9. byte[] test = new byte[3];
  10. byte[] end = new byte[test.length];
  11.  
  12. if (impossible(test)) {
  13. System.out.println(Arrays.toString(test));
  14. }
  15. do {
  16. increment(test, 0);
  17. if (impossible(test)) {
  18. System.out.println(Arrays.toString(test));
  19. }
  20. } while (!Arrays.equals(test, end));
  21.  
  22. }
  23.  
  24. private static void increment(byte[] arr, int i) {
  25. arr[i]++;
  26. if (arr[i] == 0 && i + 1 < arr.length) {
  27. increment(arr, i + 1);
  28. }
  29. }
  30.  
  31. public static boolean impossible(byte[] myBytes) throws UnsupportedEncodingException {
  32. if (myBytes.length == 0) {
  33. return false;
  34. }
  35. String string = new String(myBytes, "UTF-8");
  36. return string.length() == 0;
  37. }
Add Comment
Please, Sign In to add comment