0
0
0
1. 云栖社区>
2. 博客>
3. 正文

# 正文

## 方法一：

``````public class Number {

public static final int []num = {1, 2, 3, 4, 5};
public static int count = 0;
public static void main(String[] args) {
calculate(num);
System.out.println("总数为" + count);
}

public static void calculate(int []arr){
for(int i=0; i<arr.length; i++)
{
for(int j=0; j<arr.length; j++)
{
if(j!=i)
{
for(int k=0; k<arr.length; k++)
{
if(k!=i && k!=j){
count++;
System.out.println("第" + count + "个数为: " + arr[i] + "" + arr[j] + "" + arr[k]);
}
}
}
}
}
}

}``````

``````第1个数为: 123

## 方法二

``````import java.util.Stack;

public class Num {
public static final Stack<String> stack = new Stack<String>();
public static final int goalDigits = 3;
public static final int []num = {1, 2, 3, 4, 5};
public static int totalNum = 0;

public static void main(String[] args) {
for(int i : num){
numS(i);
}
System.out.println("总数为" + totalNum);
}

public static void numS(int i){
stack.push(i + "");
while(!stack.isEmpty()){
String iString  = stack.pop();
if(isGoal(iString)){
totalNum++;
System.out.println("第" + totalNum + "个数字为: " + Integer.parseInt(iString));
continue;
}
for(int j : num){
if(!iString.contains(j + ""))
stack.push(iString + j + "");
}
}
}

public static boolean isGoal(String s){
return s.length() == goalDigits;
}

}``````

``````第1个数字为: 154

+ 关注