Android face Test

Source: Internet
Author: User

1.Java problem

 Public classchartest {String str=NewString ("Good"); Char[] ch={' A ', ' B ', ' C '};  Public Static voidMain (String args[]) {intercontents info=Newintercontents (); Chartest ex=Newchartest ();        Ex.change (ex.str,ex.ch); System.out.println (Ex.str+ "and");                    System.out.println (ex.ch); }     Public voidChange (String str,Charch[]) {STR= "Test OK"; ch[0]= ' G ';; }}

The output is:

Goodand

Gbc

Note: Java differs from C++,java only by value (the basic type is usually passed by value, the object is the value of the copy of the object reference, and so is called by value), and CH is changed because it makes a reference copy to the function according to the reference of the CH object. The change of the elements in the array will cause the change of the array object in Ch. In addition, if you give the function no array, only a single char, then the same as STR will not change

2. Implement single-linked list reversal

 Public classnode {node next; intvalue;  PublicNode (intvalue) {         This. Value =value; }         PublicNode GetNext () {returnNext; }     Public voidSetnext (Node next) { This. Next =Next; }     Public intGetValue () {returnvalue; }     Public voidSetValue (intvalue) {         This. Value =value; }    }
/*** * Implementation of single-linked list reversal*/     Public Static voidMain (String args[]) {chartest chartest=Newchartest (); Node Head=NewNode (0); Node Node1=NewNode (1); Node Node2=NewNode (2); Node Node3=NewNode (3); Node Node4=NewNode (4); Node Node5=NewNode (5);        Head.setnext (Node1);        Node1.setnext (Node2);        Node2.setnext (NODE3);        Node3.setnext (NODE4);        Node4.setnext (NODE5); Node5.setnext (NULL); Node Head1=Chartest.reverse1 (head);                Chartest.display (HEAD1); }                /**     *      * @paramN-Head node * method: Outputs all value values of the linked list*/     Public voiddisplay (Node N) {if(n!=NULL) {System.out.println ("Value of output:" +N.getvalue ());        Display (N.next); }        Else{System.out.println ("Value of output is null"); }    }              Public Staticnode Reverse1 (node head) {        if(Head = =NULL|| Head.getnext () = =NULL) {              returnHead} Node Rehead= Reverse1 (Head.getnext ());        Head.getnext (). Setnext (head); Head.setnext (NULL);returnRehead;    }      

Note: The recursive reversal method is copy.

Android face Test

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.