public static void main(String args)

Oracle Certified Foundations Associate Java Certification Questions and Discussion
1Z0-811

Moderator: admin

Post Reply
hin1129
Posts: 9
Joined: Fri Apr 14, 2023 2:20 pm
Contact:

public static void main(String args)

Post 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?
Last edited by admin on Thu Apr 27, 2023 4:01 pm, edited 1 time in total.
Reason: Please put code inside [code] [/code]

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: public static void main(String args)

Post by admin »

What happened when you tried compiling it?
If you like our products and services, please help us by posting your review here.

hin1129
Posts: 9
Joined: Fri Apr 14, 2023 2:20 pm
Contact:

Re: public static void main(String args)

Post 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

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: public static void main(String args)

Post 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.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 13 guests