Page 1 of 1

public static void main(String args)

Posted: Thu Apr 27, 2023 3:11 pm
by hin1129

Code: Select all

public class ArgsPrinter{    
public static void main(String args){       
for(int i=0; i<3; i++){          
System.out.println(args);       
}}}
What will be printed when the above class is run using the following command line: "java ArgsPrinter 1 2 3 4"
the compiler will throw an error as its not "string[] args"

but what if it is: "java ArgsPrinter 1"
would it compile or not?

Re: public static void main(String args)

Posted: Thu Apr 27, 2023 4:01 pm
by admin
What happened when you tried compiling it?

Re: public static void main(String args)

Posted: Thu Apr 27, 2023 4:30 pm
by hin1129
not sure how to do it...
this is my path: "Desktop\DF_Java\javar-revision\src"
this is my class: "public class Main{}"
i tried:
javac Main.java
java Main
but neither has worked

Re: public static void main(String args)

Posted: Fri Apr 28, 2023 3:30 am
by admin
Well , you have follow the exact steps given by whatever book you are following. Because I don't know why you are expecting your code to work. There won't be any compilation error but what are you expecting to happen when you run it and why?
It seems to me that you are trying to jump in the middle instead of starting from the start of a chapter or a book.