/*這是一個在線測試的問題,學生在其中寫入一個函數,該函數的答案由我的'correctfunction'驗證,而這個函數對學生是隱藏的。我想比較main方法中兩個函數的結果。 */在另一個方法中訪問一種方法的局部變量
import java.util.Arrays;
class SortArr
{
static int[] arr = new int[10];
public int[] sortin(int[] ans)
{
Arrays.sort(ans);
System.out.println(Arrays.toString(ans));
return ans;
}
public int[] correctfunction(int[] sol)
{
Arrays.sort(sol);
System.out.println(Arrays.toString(sol));
return sol;
}
public static void main(String[] args)
{
arr = new int[] {4,8,3,15,2,21,6,19,11,7};
SortArr ob=new SortArr();
ob.correctfunction(arr);
ob.sortin(arr);
if(Arrays.equals(ob.sol == ob.ans)) //non-static method //equals(Object) cannot be referenced from a static context
//variable ob of type SortArr: cannot find symbol
System.out.println("correct");
else
System.out.println("incorrect");
}
}
您的代碼太糟糕了。我剛剛編輯 –
@sᴜʀᴇsʜᴀᴛᴛᴀ正在非常非常有禮貌 –
編輯完成後,我才意識到,你只是在這裏放棄了代碼。 –