Although a recursive programming style is not recommended on a Java map, I want to do a little Fibonacci test. I wrote a function that calculates the Fibonacci set for large integers (represented by arrays of bytes).
My code is as follows:
public static byte[] fibonacci(byte[] n) {
if (isLEThan1(n)) {
return n;
}
else {
return add(fibonacci(subtract(n, new byte[]{0x01})),fibonacci(subtract(n,new byte[]{0x02})));
}
}
where boolean isLEThan(byte[])returns trueif the integer represented by the byte array is less than or equal to 1 false, if not.
byte[] add(byte[], byte[])and byte[] subtract(byte[], byte[])implement addition and subtraction for large integers represented by arrays of bytes. They return a new byte array containing the result of the operation.
, , , , SystemException.NO_RESOURCE - , - .
, , 6F00 .
, :
try {
fibonacci(array);
} catch (ArithmeticException e) {
ISOException.throwIt((short) 0x0100);
} catch (ArrayStoreException e) {
ISOException.throwIt((short) 0x0200);
} catch (APDUException e) {
ISOException.throwIt(Util.makeShort((byte) 0x03,
(byte) e.getReason()));
} catch (CryptoException e) {
ISOException.throwIt(Util.makeShort((byte) 0x04,
(byte) e.getReason()));
} catch (ISOException e) {
ISOException.throwIt(Util.makeShort((byte) 0x05,
(byte) e.getReason()));
} catch (PINException e) {
ISOException.throwIt(Util.makeShort((byte) 0x06,
(byte) e.getReason()));
} catch (ServiceException e) {
ISOException.throwIt(Util.makeShort((byte) 0x07,
(byte) e.getReason()));
} catch (SystemException e) {
ISOException.throwIt(Util.makeShort((byte) 0x08,
(byte) e.getReason()));
} catch (TransactionException e) {
ISOException.throwIt(Util.makeShort((byte) 0x09,
(byte) e.getReason()));
} catch (ClassCastException e) {
ISOException.throwIt((short) 0x0A00);
} catch (IndexOutOfBoundsException e) {
ISOException.throwIt((short) 0x0B00);
} catch (NegativeArraySizeException e) {
ISOException.throwIt((short) 0x0C00);
} catch (NullPointerException e) {
ISOException.throwIt((short) 0x0D00);
} catch (SecurityException e) {
ISOException.throwIt((short) 0x0E00);
}
}
, - ?