It seems like people like to make a spoon, so I decided to post the worst solution for an easy task:
public static boolean isNumber(String s) throws Exception { boolean result = false; byte[] bytes = s.getBytes("ASCII"); int tmp, i = bytes.length; while (i >0 && (result = ((tmp = bytes[--i] - '0') >= 0) && tmp <= 9)); return result; }
About the worst code I could imagine, but there may be other people who can come up with even worse solutions.
Hm, containsNumber is worse:
public static boolean containsNumber(String s) throws Exception { boolean result = false; byte[] bytes = s.getBytes("ASCII"); int tmp, i = bytes.length; while (i >0 && (true | (result |= ((tmp = bytes[--i] - '0') >= 0) && tmp <= 9))); return result; }
Kaj Jun 14 2018-11-11T00: 00Z
source share