JDK:jdk1.8.0_192Eclipse:Eclipse JAVA Photon這份代碼不會(huì)報(bào)錯(cuò):但是這份代碼報(bào)錯(cuò):報(bào)錯(cuò)如圖:明明代碼是一樣的吧?但報(bào)錯(cuò)代碼加上個(gè):j=i+1;就不報(bào)錯(cuò)了:我貼下報(bào)錯(cuò)的代碼:package com.Two;
class Demo01 {
public int[] twoSum(int[] nums, int target) {
for(int i=0;i<nums.length;i++){
for(int j=i+1;j<nums.length;j++);{
if(nums[j] == target - nums[i]){
return new int[] {i,j};
}
}
}
throw new IllegalArgumentException("No two sum solution");
}
}這是不報(bào)錯(cuò)的代碼:package com.Two;
class Test{
public int[] twoSum(int[] nums, int target) {
for (int i = 0; i < nums.length; i++) {
for (int j = i + 1; j < nums.length; j++) {
if (nums[j] == target - nums[i]) {
return new int[] { i, j };
}
}
}
throw new IllegalArgumentException("No two sum solution");
}
}是什么原因呢?你們用這代碼會(huì)報(bào)錯(cuò)嗎?
3 回答

慕尼黑8549860
TA貢獻(xiàn)1818條經(jīng)驗(yàn) 獲得超11個(gè)贊
用的IDEA 并沒(méi)有報(bào)錯(cuò) eclipse也已經(jīng)提示要重新定義j了
添加回答
舉報(bào)
0/150
提交
取消