无聊看博客有说不用if判断两个数的大小 看回复的思路弄了个 很蛋疼 很痛很痛 代码
public static int compare(int a,int b){ int compare = 0; int max = 0; int fh = 1; int cha = a-b; try { int[] aArr = new int[a];//判断a的符号 过去了说明a>=0 int[] bArr = null; try { bArr = new int[b];//判断b的符号 过去了说明b>=0 进入a b都大于0的情况 try { aArr[b] = a;//过去了说明a>b max = a; compare = 1; } catch (Exception e) {//b>=a try { bArr[a] = b; //过去了说明b>a max = b; compare = -1; } catch (Exception e1) {//b=a compare = 0; max = a; } } } catch (Exception e) { //b<0 则a正b负 a>b compare = 1; max = a; } } catch (Exception e) { //a <0; try { int[] bArr = new int[b]; //过去了说明b>0 a负b正b>a max = b; compare = -1; } catch (Exception e1) {//a b 都为负数 fh = -1; int[] aArr2 = new int[a*fh]; try { aArr2[fh*b] = a*fh; // 说明-b<-a 即b>a max = b; compare = -1; } catch (Exception e2) {//|b|>=|a| int[] bArr2 = new int[b*fh]; try { bArr2[fh*a] = b*fh;// -a<-b 即a>b max = a; compare = 1; } catch (Exception e3) { //-a = -b 即a=b max = a; compare = 0; } } } } System.out.println(compare+"==="+max); return a; }
弄完之后发现 真TM蛋疼 于是又有下面的代码:
public static int compare(int a,int b){ int cha = a-b; try { int[] arr = new int[cha]; try { int[] arr2 = new int[-cha]; System.out.println(a+"="+b); } catch (Exception e) { System.out.println(a+">"+b); } } catch (Exception e) { System.out.println(b+">"+a); } }
无聊蛋疼了 啦啦啦