Team competitor sorting (java object-oriented code solution)

Source: Internet
Author: User
Package wzs. arithmetics; import java. util. ArrayList; import java. util. List; // question: two table tennis teams compete, each with three players. Team a is a, B, and c, and Team B is x, y, and z. // The Game list has been determined by lottery. Someone asked the players about the game list. A said that he is not in comparison with x, c said that he is not in comparison with x and z. please compile a program to find a list of three-team players. Public class Test_wzs17 {public static void main (String [] args) {// sorting of Team a members, fixed Pingpang team1Member = new Pingpang ("a", "B ", "c"); System. out. println ("Team A:" + team1Member); // Team B member String [] team2Member = {"x", "y", "z "}; // All sorting tasks of Team B may be List <Pingpang> team2List = new ArrayList <Pingpang> (); // temporary sorting of Team B, Pingpang tempTemp; for (int I = 0; I <3; I ++) {for (int j = 0; j <3; j ++) {for (int k = 0; k <3; K ++) {tempTemp = new Pingpang (team2Member [I], team2Member [j], team2Member [k]); // The team members do not repeat if (! TempTemp. member1.equals (tempTemp. member2 )&&! TempTemp. member2.equals (tempTemp. member3) {// a: He doesn't compare with x. c: He doesn't compare with x. z: if (! TempTemp. member1.equals ("x ")&&! TempTemp. member3.equals ("x ")&&! TempTemp. member3.equals ("z") {// System. out. println ("Team B:" + tempTemp); team2List. add (tempTemp) ;}}}}for (Pingpang pingpang: team2List) {System. out. println ("B:" + pingpang) ;}}/ *** table tennis team * @ author wWX154783 ***/class Pingpang {String member1; // member 1 String member2; // Member 2 String member3; // member 3 public Pingpang () {} public Pingpang (String member1, String member2, String member3) {this. member1 = member1; this. member2 = member2; this. member3 = member3;} @ Override public String toString () {return "team member {" + member1 + "," + member2 + "," + member3 + "}";}}

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.