【发布时间】:2014-11-07 18:24:45
【问题描述】:
首先请注意,我了解 Java。我进行了一个暴力破解应用程序,我知道密码中有两个数字要破解。
当我生成一个像ABC这样的字符串时,我需要在这个字符串的所有可能的位置放置两个数字(我已经做到了!)
我需要两个分别从 0 到 9 生成的数字。这包括两个数字放在一起时从 00 到 99 的可能性。
我已经考虑了很多,并认为让一个整数递增然后我可以分成两个整数反馈给我的主数可能是一个更好的主意,但是我实际上不能从 00 开始一个整数, 01, 02, 03.. 其中第一个位置是 fNum 和第二个 sNum。 1、2、3、4 到 10 点。
到目前为止,我已经提出了以下解决方案,但它也没有像我想要的那样工作..
public int twoNumber(int fNum, int sNum){
//form array from two integers
int[] intArray = {fNum, sNum};
//increment the array value (not sure if correct way?)
intArray++;
//split the array to get two indiivudla numbers
int[] part1 = new int[99];
int[] part2 = new int[99];
System.arraycopy(intArray, 0, part1, 0, part1.length);
System.arraycopy(intArray, part1.length, part2, 0, part2.length);
//I need to convert the two above and return the two numbers as integers
//and not arrays
}
我不是 100% 确定这是执行此操作的最佳方法,但程序应返回如下内容:
假设我们从暴力中的 A 开始。
0A0
0A1
0A3
..
0A9
1A0
..
9A9
..
0AB0
0AB1
0AB2
0AB3
等等。
我的问题是,解决这个问题的最佳方法是形成一个数组、递增、拆分和返回吗?我还考虑过其他方法,例如创建所有可能数字的数组(花费太长时间)、在 java 中使用随机数、创建单个整数、递增、拆分和返回。
【问题讨论】:
标签: java arrays integer helpers