public class Stuff { public static int[] genArray(int size) { int[] arr=new int[size]; for (int i=0;iarr[i]) biggest=false; if (biggest) return arr[i]; } return -1; //Literally can't happen } public static int muchBetter(int[] arr) { int guess=arr[0]; for (int i=1;iguess) guess=arr[i]; return guess; } public static void main(String[] args) { final int SIZE=100000; int largest; long start,stop; int[] arr; arr=genArray(SIZE); System.out.println("Starting size: "+SIZE); start=System.currentTimeMillis(); largest=soBad(arr); stop=System.currentTimeMillis(); System.out.println("Largest: "+largest); System.out.println("Time elapsed: "+(stop-start)+"ms"); System.out.println(); start=System.currentTimeMillis(); largest=muchBetter(arr); stop=System.currentTimeMillis(); System.out.println("Largest: "+largest); System.out.println("Time elapsed: "+(stop-start)+"ms"); arr=genArray(SIZE*2); System.out.println("Starting size: "+2*SIZE); start=System.currentTimeMillis(); largest=soBad(arr); stop=System.currentTimeMillis(); System.out.println("Largest: "+largest); System.out.println("Time elapsed: "+(stop-start)+"ms"); System.out.println(); start=System.currentTimeMillis(); largest=muchBetter(arr); stop=System.currentTimeMillis(); System.out.println("Largest: "+largest); System.out.println("Time elapsed: "+(stop-start)+"ms"); } }