Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Java certification question

Status
Not open for further replies.

deva1

Programmer
Oct 28, 2002
27
US
Hi All,

I new to java .I was going through java certification questions in javaprepare.com.

1.What all gets printed on the standard output when the class below is compiled and executed by entering "java test lets see what happens". Select the two correct answers.

public class test {
public static void main(String args[]) {
System.out.println(args[0]+" "+args.length);
}
}

ans:
A.java
B.test
C.lets
D.3
E.4
F.5
G.6

I thought the answer is A G.But what I am seeing on the web site C E.

Can anyone tell the right answer and explain me ?




 
If you type this (as you have posted)

Code:
"java test lets see what happens".

then the output should be (on Windows) :

Code:
C:\java>"java test lets see what happens"
'"java test lets see what happens"' is not recognized as an internal or external command,
operable program or batch file.

If you type this :

Code:
C:\java>java test "lets see what happens"
lets see what happens 1

Code:
C:\java>java test lets "see what happens"
lets see what happens 1

Code:
C:\java>java test lets "see what happens"
lets 2

Because its all about the quotation marks - if you encapuslate a String such as "abc def" then java takes that as one parameter from the command line.

If you type in :

abc "def hjk"

then it will see two ...

Does this make sense ?
 
However, if the quotes were intended to mean this is the command, then if you use this as the command line:
java test lets see what happens
you get this as output:
lets 4

because the first argument 'args[0]' is 'lets' and there are 4 arguments 'args.length'.

[blue]"Well, once again my friend, we find that science is a two headed beast. One head is nice, it gives us aspirin and other modern conveniences,...but the other head of science is BAD! Oh, beware the other head of science, Arthur; it bites!!" - The Tick[/blue]
 
Excellent ,now I know how they got C E as answer.


Thank you sir
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top