密码的业务规则密码位数为6-16个字符,区分大小写,支持字母(a-z,A-Z)、数字(0-9)及“_~@#$^”符号 代码如下(示例):^[A-Za-z0-9_~@#$^]{6,16}+$
import java.math.BigIntegerimport java.util.*
public class PermutationGenerator {
private int[] a
private BigInteger numLeft
private BigInteger total
public PermutationGenerator(int n) {
if (n <1) {
throw new IllegalArgumentException("Min 1")
}
a = new int[n]
total = getFactorial(n)
reset()
}
public void reset() {
for (int i = 0i <a.lengthi++) {
a[i] = i
}
numLeft = new BigInteger(total.toString())
}
public BigInteger getNumLeft() {
return numLeft
}
public BigInteger getTotal() {
return total
}
public boolean hasMore() {
return numLeft.compareTo(BigInteger.ZERO) == 1
}
private static BigInteger getFactorial(int n) {
BigInteger fact = BigInteger.ONE
for (int i = ni >1i--) {
fact = fact.multiply(new BigInteger(Integer.toString(i)))
}
return fact
}
public int[] getNext() {
if (numLeft.equals(total)) {
numLeft = numLeft.subtract(BigInteger.ONE)
return a
}
int temp
// Find largest index j with a[j] <a[j+1]
int j = a.length - 2
while (a[j] >a[j + 1]) {
j--
}
// Find index k such that a[k] is smallest integer
// greater than a[j] to the right of a[j]
int k = a.length - 1
while (a[j] >a[k]) {
k--
}
// Interchange a[j] and a[k]
temp = a[k]
a[k] = a[j]
a[j] = temp
// Put tail end of permutation after jth position in increasing order
int r = a.length - 1
int s = j + 1
while (r >s) {
temp = a[s]
a[s] = a[r]
a[r] = temp
r--
s++
}
numLeft = numLeft.subtract(BigInteger.ONE)
return a
}
//程序测试入口
public static void main(String[] args) {
int[] indices
String[] elements = { "a", "b", "c"}
PermutationGenerator x = new PermutationGenerator(elements.length)
StringBuffer permutation
while (x.hasMore())
{
permutation = new StringBuffer("%")
indices = x.getNext()
for (int i = 0i <indices.lengthi++) {
permutation.append(elements[indices[i]]).append("%")
}
System.out.println(permutation.toString())
}
}
}
先给你一个看看!
具体如下:java字符串数组合并,可以使用array.copy复制方法,如下代码:
package com.qiu.lin.he
import java.text.ParseException
import java.util.Arrays
public class Ceshi {
public static void main(String[] args) throws ParseException {
String[] str1 = { "J", "a", "v", "a", "中" }
String[] str2 = { "如", "何", "把", "两", "个", "数", "组", "合", "并", "为",
"一", "个" }
int strLen1 = str1.length// 保存第一个数组长度
int strLen2 = str2.length// 保存第二个数组长度
str1 = Arrays.copyOf(str1, strLen1 + strLen2)// 扩容
System.arraycopy(str2, 0, str1, strLen1, strLen2)// 将第二个数组与第一个数组合并
System.out.println(Arrays.toString(str1))// 输出数组
}
}