package first.test.Demo;
public class ForLoop {
public static void main(String[] args) throws Exception {
String password = new RandomString().main();
System.out.println(password);
String targetList[] = new String[] {"0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
String temp = "";
for (int i1 = 0; i1 < targetList.length; i1++) {
for (int i2 = 0; i2 < targetList.length; i2++) {
for (int i3 = 0; i3 < targetList.length; i3++) {
for (int i4 = 0; i4 < targetList.length; i4++) {
for (int i5 = 0; i5 < targetList.length; i5++) {
temp = targetList[i1] + targetList[i2] + targetList[i3] + targetList[i4] + targetList[i5];
if (password.equals(temp)) {
System.out.println("i1 = " + i1);
System.out.println("i2 = " + i2);
System.out.println("i3 = " + i3);
System.out.println("i4 = " + i4);
System.out.println("i5 = " + i5);
break;
}
}
if (password.equals(temp)) {
break;
}
}
if (password.equals(temp)) {
break;
}
}
if (password.equals(temp)) {
break;
}
}
if (password.equals(temp)) {
break;
}
}
System.out.println("找到目标密码为:" + temp);
}
}
这里用break终止循环,因为每次只能终止一个for,所以要终止5回。