---
title: "C语言趣味程序百例精解之JAVA实现(56)区分旅客国籍 "
author: "dearbaba2011"
date: "2011-11-02T10:58:54Z"
tags: []
categories: ["编程语言"]
slug: "c-java-56"
draft: false
lastmod: "2011-11-02T10:58:54Z"
id: 1229679
url: "https://dearbaba2011.iteye.com/blog/1229679"
---

C语言趣味程序百例精解之JAVA实现（56）区分旅客国籍

![](http://www.javaxxz.com/attachment/thumb/Mon_1111/66_1_225460c373e8d24.jpg "点击查看原图")  
![](http://www.javaxxz.com/attachment/thumb/Mon_1111/66_1_52b9f36ce3e3c56.jpg "点击查看原图")

程序：

public class Test56{  
   public static void main(String args\[]){  
      new Test56().whereAreYouFrom56();  
   }

   /\**    
     * 56。区分旅客国籍    
     *    
     * 1美国，2德国,3英国,4法国,5俄罗斯,6意大利    
     \*/    
    public void whereAreYouFrom56() {    
        int count = 0;    
        for (int a = 1; a &lt;= 6; a++)    
            for (int b = 1; b &lt;= 6; b++)    
                for (int c = 1; c &lt;= 6; c++)    
                    for (int d = 1; d &lt;= 6; d++)    
                        for (int e = 1; e &lt;= 6; e++)    
                            for (int f = 1; f &lt;= 6; f++)    
                                if (a != 1    
                                        && a != 5    
                                        && a != 2    
                                        && e != 1    
                                        && e != 2    
                                        && e != 5    
                                        && c != 2    
                                        && c != 1    
                                        && c != 5    
                                        && b != 2    
                                        && f != 2    
                                        && a != 4    
                                        && c != 6    
                                        && b != 1    
                                        && c != 4    
                                        && notEquls(new int\[] { a, b, c, d, e,    
                                                f })) {    
                                    count++;    
                                    System.out.print(" a=" + a);    
                                    System.out.print(" b=" + b);    
                                    System.out.print(" c=" + c);    
                                    System.out.print(" d=" + d);    
                                    System.out.print(" e=" + e);    
                                    System.out.println(" f=" + f);    
                                }    
        System.out.println("Count =" + count);    
    }    
   /\**    
     * 判断是否两两不相等    
     \*/    
    public boolean notEquls(int\[] a) {    
        if (a == null || a.length == 0 || a.length == 1)    
            return true;    
        for (int i = 0; i &lt; a.length; i++) {    
            for (int j = 0; j &lt; a.length; j++) {    
                if (a *== a\[j] && i != j) {*    
                    *// System.out.println("a\[" + i + "]" + a + " a[" + j +*    
                    *// "]"*    
                    *// + a\[j] + "---");*    
                    *return false;*    
                *}*    
            *}*    
        *}*    
        *return true;*    
    *}*    
*}*  
*C:\\bat&gt;java   Test56*  
*a=6 b=5 c=3 d=2 e=4 f=1*  
*Count =1*  
*a是意大利人，B是俄罗斯人,c是英国人，D是德国人，E是法国人，F是美国人。*

分享自：[http://blog.csdn.net/dearbaba2011/article/details/6927500](http://blog.csdn.net/dearbaba2011/article/details/6927500)