Question 134 / 297:  What is the result of running the following program (which was compiled fine) given the command line:

java Tester one two

public class Tester {

public static void main(String[] args) {

if (args.length > 0)

for (String str : args)

System.out.print(str);

System.out.print("--");

}

}

A  one--two--
B  onetwo
C  onetwo--
D  Tester--one--two--
E  Testeronetwo--
<< First < Previous Next > Last >>
Explanation:

Be careful of the braces, the System.out.print("--") is not included in the for loop block, so it will be executed once after the loop is finished

java Tester one two

The first argument represents the name of the class, and what come after are the program arguments.

Exam Home Page
Ask
Copy and paste the following HTML code into your website or blog.
<iframe src="https://www.jobilize.com/embed/java-certification-questions" width="600" height="600" frameborder="0" marginwidth="0" marginheight="0" scrolling="yes" style="border:1px solid #CCC; border-width:1px 1px 0; margin-bottom:5px" allowfullscreen webkitallowfullscreen mozallowfullscreen> </iframe>