Interface Test Course the first day, mainly Java basic knowledge, the teacher left two jobs, the completion of the job is as follows
First job:
Importjava.util.ArrayList;ImportJava.util.HashSet;Importjava.util.List;ImportJava.util.Set;//First Homework//UserID, put the following userid into the list, and then remove the duplicate userid. //1111//2222// A//333// A//3333//333//555//666 Public classHomework1 { Public Static voidMain (String args[]) {//put the UserID in the listList<string> userlist =NewArraylist<string>(); Userlist.add ("1111"); Userlist.add ("2222"); Userlist.add ("22"); Userlist.add ("333"); Userlist.add ("22"); Userlist.add ("3333"); Userlist.add ("333"); Userlist.add ("555"); Userlist.add ("666"); //put the values in the userlist into the set to go heavySet<string> Userset =NewHashset<string>(); for(String userid:userlist) {userset.add (userid); } //Empty userlistuserlist.clear (); //re-place the values in the set into UserList for(String userid:userset) {userlist.add (userid); } //Print the UserID in the UserList for(String userid:userlist) {System.out.println (userid); } }}
Second job:
Importjava.util.ArrayList;Importjava.util.List;//a second homework////Xiao Hong has 3 apples, xiaoming has 8 apples, Xiao Li has 5 apples, Xiao Zhang has 2 apples, and Xiao Wang has 7 apples .//One way: Ask who has the most apples//The second method: Ask who has the least Apple//The third method: According to the Apple number from big to small sort, print the user's name and the number of apples Public classHOMEWORK2 { Public Static voidMain (string[] args) {string[][] Userarray= {"Small red", "3"}, {"Xiaoming", "8"}, {"Xiao Li", "5" }, { "Xiao Zhang", "2"}, {"Xiao Wang", "7" } }; //adding people to the listList<user> userlist =NewArraylist<user>(); for(string[] user:userarray) {User NewUser=NewUser (); Newuser.setusername (user[0]); Newuser.setapplenumber (user[1]); Userlist.add (NewUser); } System.out.println ("The person with the most apples is:"); Prtuser (Findmax (userlist)); System.out.println ("The person with the fewest apples is:"); Prtuser (Findmin (userlist)); System.out.println ("By Apple number from big to small sort:"); for(User User:orderuser (userlist)) {prtuser (user); } } Public Static voidprtuser (user user) {System.out.println (User.getusername ()+ "have" +User.getapplenumber ()+ "an apple"); } //find people who have the most apples Public StaticUser Findmax (list<user>userlist) {User Maxuser= Userlist.get (0); for(User user:userlist) {if(Integer.parseint (Maxuser.getapplenumber ()) <Integer. parseint (User.getapplenumber ())) {Maxuser=user; } } returnMaxuser; } //find people with the fewest apples Public StaticUser Findmin (list<user>userlist) {User Minuser= Userlist.get (0); for(User user:userlist) {if(Integer.parseint (Minuser.getapplenumber ()) >Integer. parseint (User.getapplenumber ())) {Minuser=user; } } returnMinuser; } //The number of apples is sorted from large to small Public StaticList<user> Orderuser (list<user>userlist) {User Useri, Userj=NULL; for(inti = 0; I <= userlist.size ()-1; i++) { for(intj = i + 1; J <= Userlist.size ()-1; J + +) {Useri=Userlist.get (i); Userj=Userlist.get (j); if(Integer.parseint (Useri.getapplenumber ()) <Integer. parseint (Userj.getapplenumber ())) {Userlist.set (J, Useri); Userlist.set (i, USERJ); } } } returnuserlist; }}
//To create the user class://name//Number of apples////These properties are decorated with private Public classUser {//User name PrivateString UserName; //number of apples owned by the user PrivateString Applenumber; PublicString GetUserName () {returnUserName; } Public voidsetusername (String userName) { This. UserName =UserName; } PublicString Getapplenumber () {returnApplenumber; } Public voidSetapplenumber (String applenumber) { This. Applenumber =Applenumber; }}
The main learning of Java Basic Principles, constructors, basic types, String, List, map and debugging and other related content, not just a simple explanation, but also through practice to familiarize with the relevant knowledge.
Interface Test First day