Arrange and combine the four numbers of 1234 into unordered and non-repeating three-digit numbers

package com.interview07;

/**
 * Copyright (C), 2018-2021
 * FileName: Demo2
 * Author:   kongfanyu
 * Date:     2021/3/10 19:10
 * 对1234四个数排列组合成无序且不重复的三位数
 */
public class Demo2 {
    public static void main(String[] args) {
        int line = 0;
        for (int i = 1; i <=4 ; i++) {
            for (int j = 1; j <=4 ; j++) {
                for (int k = 1; k <=4 ; k++) {
                    if ( i!= j && j != k && i != k  ) {
                        if(j != i + 1 || k != j + 1 ) {
                            line++;
                            System.out.println("" + i + j + k + "\t");
                            if (line % 5 == 0) {
                                System.out.println();
                            }
                        }
                    }
                }
            }
        }
    }
}

 

Supongo que te gusta

Origin blog.csdn.net/kongfanyu/article/details/114643716
Recomendado
Clasificación