Example one:
Public class INC { publicstaticvoid main (string[] args) { INC inc=New Inc (); int i=5; Inc.fermin (i); I=i++; // temp=i;i++;i=temp; System.out.println (i); } void Fermin (int i) { i+ +; }}
The result is:
5
Example two: Insert sort, array out of bounds
Public classinsertsort{ Public Static int[] Sort (int[] intarray) { intSize=intarray.length; for(inti=1;i<size;i++){ for(intJ=i;intarray[j]<intarray[j-1] && J > 0;j--) { intTemp=intarray[j-1]; Intarray[j-1]=Intarray[j]; INTARRAY[J]=temp; } } returnIntarray; } Public Static voidMain (string[] args) {int[] arr={2,5,7,1,6,11,3,8}; //Insert SortInsertsort.sort (arr); for(intI:arr) {System.out.println (i); } }}
Results:
Java.lang.ArrayIndexOutOfBoundsException
Enter two breakpoints, F6 key debugging.
The revised version is as follows:
Public classinsertsort{ Public Static int[] Sort (int[] intarray) { intSize=intarray.length; for(inti=1;i<size;i++){ for(intJ=i; J > 1&&intarray[j]<intarray[j-1];j--) { intTemp=intarray[j-1]; Intarray[j-1]=Intarray[j]; INTARRAY[J]=temp; } } returnIntarray; } Public Static voidMain (string[] args) {int[] arr={2,5,7,1,6,11,3,8}; //Insert SortInsertsort.sort (arr); for(intI:arr) {System.out.println (i); } }}
A sort from small to large.
Java interview written test talk