Discussion
public class Myfile
{
public static void main (String[] args)
{
String biz = args[1];
String baz = args[2];
String rip = args[3];
System.out.println("Arg is " + rip);
}
}
| Select how you would start the program to cause it to print: Arg is 2 |
Answer: C
Correct answer: java Myfile 1 3 2 2
The program prints args[3], and command line arguments are indexed from zero, so args[3] is the *fourth* one. With the arguments 1, 3, 2, 2 the fourth is 2, giving “Arg is 2”. The invocation with 0 1 2 3 would print 3, and the one with five arguments would also print 3 - both losing a place to the zero-based indexing.
No comment is present. Be the first to comment.
Loading…
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development