Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public boolean impossible(byte[] myBytes) {
- if (myBytes.length == 0)
- return false;
- String string = new String(myBytes, "UTF-8");
- return string.length() == 0;
- }
- public static void main(String[] args) throws UnsupportedEncodingException {
- byte[] test = new byte[3];
- byte[] end = new byte[test.length];
- if (impossible(test)) {
- System.out.println(Arrays.toString(test));
- }
- do {
- increment(test, 0);
- if (impossible(test)) {
- System.out.println(Arrays.toString(test));
- }
- } while (!Arrays.equals(test, end));
- }
- private static void increment(byte[] arr, int i) {
- arr[i]++;
- if (arr[i] == 0 && i + 1 < arr.length) {
- increment(arr, i + 1);
- }
- }
- public static boolean impossible(byte[] myBytes) throws UnsupportedEncodingException {
- if (myBytes.length == 0) {
- return false;
- }
- String string = new String(myBytes, "UTF-8");
- return string.length() == 0;
- }
Add Comment
Please, Sign In to add comment