zoukankan      html  css  js  c++  java
  • 新华三:1234组成三位数不重复各种类输出

    题目:

    1 2 3 4四个数字,取3个组成三位数,有多少种类?

    4*3*2 = 24种。

    各种类输出:

    Java:

     1 public class Main {
     2     
     3     public static void main(String[] args) {
     4         int[] a = {1, 2, 3, 4};
     5         int[] state = {0, 0, 0, 0};
     6         int count=0;
     7         for(int i = 0; i < 4; i++){
     8             int num_1 = a[i]*100;
     9             state[i] =1;
    10             for(int j = 0; j < 4 ; j++){
    11                 if(state[j] == 0){
    12                     int num_2 = num_1 + a[j]*10;
    13                     state[j] = 1;
    14                     for(int k = 0; k < 4 ; k++){
    15                         if(state[k] == 0){
    16                             int num_3 = num_2 + a[k];
    17                             System.out.println(num_3);
    18                             count++;
    19                         }
    20                     }
    21                     state[j] = 0;
    22                 }
    23             }
    24             state[i] =0;
    25         }
    26         System.out.println(count);
    27     }
    28 }
  • 相关阅读:
    git
    oracle object_id和data_object_id的区别
    statspack系列8
    statspack系列7
    statspack系列6
    statspack系列5
    statspack系列4
    statspack系列3
    statspack系列2
    MySQL源码之两阶段提交
  • 原文地址:https://www.cnblogs.com/zdtiio/p/7577382.html
Copyright © 2011-2022 走看看