Java loop exercise: A lie at the wedding

Source: Internet
Author: User

package practicego;/** *  Wedding lies            three grooms for a, B, C, three Brides for x, Y, Z.           someone wants to know who the hell is marrying,           then asked the new three people, get the following tips:    a said he will marry X,    x said her fiance is c,    C said he would marry Z.           the man later knew they were joking, all lies,            So, who is marrying who?    */public class cto {public static void main (String[] args )  {system.out.println ("x-1  y-2  z-3"); for (int a=1; a<=3; a++) {for ( int b=1; b<=3; b++) {for (int c=1; c<=3; c++) {if (a!=1&&c!=1& &c!=3&&a!=b&&b!=c&&a!=c) {System.out.println ("a=" +a); System.out.println ("b=" +b); System.out.println ("c=" +c);}}}} 

Operation Result:

X-1 Y-2 z-3a=3b=1c=2


Java loop exercise: A lie at the wedding

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.