Java interview written test talk

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.