Packagecome; Public classMarothon { Public Static voidFirstName (string[] ARGS1,int[] args2) { intMinindex,mintime,i; Mintime= 10000; Minindex= 0; for(i = 0; i < i++;){ if(Args2[i] <mintime) {Mintime=Args2[i]; Minindex=i; }} System.out.println (Args1[minindex]+ " "+mintime); } Public Static voidSecondname (string[] ARGS1,int[] args2) { intSmallindex,smallerindex,small,smaller,i; Small= 10000; Smaller= 10000; Smallerindex= 100; Smallindex=101; for(i = 0; i<16; i++){ if(Args2[i] < Small && Args2[i] >Smaller) {Small=Args2[i]; Smallindex=i; }Else if(Args2[i] <Smaller) {Small=Smaller; Smaller=Args2[i]; Smallindex=Smallerindex; Smallerindex=i; }} System.out.println (Args1[smallindex]+ " " +Args2[smallindex]); } Public Static voidMain (string[] args) {//TODO auto-generated Method StubString[] names = {"Elena", "Thomas", "Hamilton", "Suzie", "Phil", "Matt", "Alex", "Emma", "John", "James", "Jane", "Emily", "Daniel", "Neda", "Aaron", "Kate"}; int[] times = {341, 273, 278, 329, 445, 402, 388, 275, 243, 334, 412, 393, 299, 343, 317, 265}; Secondname (Names,times);}}
View Code
The Secondname function only iterates through the array once, greatly increasing the previous want to use FirstName traversal once with if to avoid the smallest to do, but will traverse two times, hahaha, good
MIT Java Open Course Assignment #2