为什么这样写会报错?public class Test
{
static String[] str1 = {"01", "02", "03", "04", "05", "06", "07", "08", "09", "10"};
static String make() {
String value = "";
for (int i=0; i<str1.length; i++) {
for (int j=0; i<str1.length; j++) {
if(str1[i].equals(str1[j]) == false){
value = value + str1[i] + " " + str1[j] + "\n";
}
}
}
return value;
}
public static void main(String[] args) {
System.out.print(make());
}
}报错如下:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 10
at Test.make(Test.java:9)
at Test.main(Test.java:18)
{
static String[] str1 = {"01", "02", "03", "04", "05", "06", "07", "08", "09", "10"};
static String make() {
String value = "";
for (int i=0; i<str1.length; i++) {
for (int j=0; i<str1.length; j++) {
if(str1[i].equals(str1[j]) == false){
value = value + str1[i] + " " + str1[j] + "\n";
}
}
}
return value;
}
public static void main(String[] args) {
System.out.print(make());
}
}报错如下:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 10
at Test.make(Test.java:9)
at Test.main(Test.java:18)
static String[] str1 = { "01", "02", "03", "04", "05", "06", "07", "08",
"09", "10" };
static String make() {
String value = "";
for (int i = 0; i < str1.length; i++) {
for (int j = 0; j < str1.length; j++) {//LZ这里的j写成i了
if (str1[i].equals(str1[j]) == false) {
value = value + str1[i] + " " + str1[j] + "\n";
}
}
}
return value;
} public static void main(String[] args) {
System.out.print(make());
}
}
for (int j=0; i<str1.length; j++) {
for (int j=0; i<str1.length; j++) {
我现在知道了什么叫马马虎虎
for (int j=0; i<str1.length; j++) {
呵呵 一般看不出来
if (str1[i].equals(str1[j]) == false) {
value = value + str1[i] + " " + str1[j] + "\n";
}
}