幾個編譯時錯誤
您沒有通過該方法的正確參數:
getRandomPrints({"a" , "b" ,"c" , "d"});// not a valid array
這裏也有一些修改:
System.out.printLn("Hello World" + args);
`l`^ note `s`^^ semicolon was missing
你既可以試試這個:
public static void main(String[] args) {
getRandomPrints(new String[]{"a" , "b" ,"c" , "d"});//creating new array of string
}
public static void getRandomPrints(String[] args){
for(String s : args)
System.out.println(s);
}
或varargs
:
public static void main(String[] args) {
getRandomPrints("a" , "b" ,"c" , "d");
}
public static void getRandomPrints(String... args){//varargs to handle csv as array
for(String s : args)
System.out.println(s);
}
或split()
:
public static void main(String[] args) {
getRandomPrints("a,b,c,d".split(","));
}
public static void getRandomPrints(String[] args){
for(String s : args)
System.out.println(s);
}
那麼,它不會編譯下手... – MadProgrammer 2014-12-08 04:53:40