我想知道如何檢查方法中的args.length。傳遞數組通過方法(java命令行參數)
例如:
public static void commandLineCheck (int first, int second){
if (args.length==0){
//do something with first and second
}
}
public static void main(String[] args) {
int first = Integer.parseInt(args[0]);
int second = Integer.parseInt(args[1]);
commandLineCheck(first, second);
}
我得到一個 「無法找到符號:ARGS」 錯誤當我這樣做。現在,我想我還需要通過args []方法。我試過這個,但它給了我一個「」錯誤。對此有沒有一個初學者友好的解決方案?
編輯:非常感謝你的快速回復傢伙!有效!