- int n = 0;
- int[] arr = {0,1,2,3,4};
- for (int i = 1; i < arr.length; i++) {
- for (int j = 1; j < arr.length; j++) {
- for (int k = 1; k < arr.length; k++) {
- if(arr[i] != arr[j] && arr[i] != arr[k])
- {
- if(arr[j] != arr[k])
- {
- int num = arr[k]+arr[j]*10+arr[i]*100;
- System.out.println(num);
- n++;
- }
- }
- }
- }
- }
- System.out.println("能组成"+n+"个互不相同且无重复数字的三位数");
- }
复制代码
有没有更简单的办法 |
|