package com.demo2; /** * Created by 莫文龙 on 2018/4/2. */ //有1,2,3,4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少 public class Demo1 { public static void main(String[] args) { int[] arr = {1,2,3,4}; int count = 0; for (int i = 0 ; i < arr.length ; i ++) { //百位 int a = arr[i]; for (int j = 0; j < arr.length ; j ++) { if (j == i) continue; //十位 int b = arr[j]; for (int k = 0 ; k < arr.length ; k ++) { if (k == i || k == j) continue; int c = arr[k]; System.out.println(a * 100 + b * 10 + c); count ++; } } } System.out.println("共有" + count + "个"); } }
50道编程题之11:有1,2,3,4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少?
猜你喜欢
转载自blog.csdn.net/weixin_38104426/article/details/79806876
今日推荐
周排行