Java Programming - Java.lang Class - Discussion

Discussion Forum : Java.lang Class - General Questions (Q.No. 4)
4.
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
java Myfile 222
java Myfile 1 2 2 3 4
java Myfile 1 3 2 2
java Myfile 0 1 2 3
Answer: Option
Explanation:

Arguments start at array element 0 so the fourth arguement must be 2 to produce the correct output.

Discussion:
33 comments Page 2 of 4.

Palak said:   8 years ago
Thanks, @Ted.

Your explanation is very helpful to understand.

Vijaya said:   7 years ago
I Am not understanding please explain correctly.

Harish said:   7 years ago
'java Myfile' is written to run the program after compilation and it's not an argument. Actually arguments start from 1.
args[0]=1
args[1]=3
args[2]=2
args[3]=2

So, option C is the correct answer.

Anil said:   6 years ago
I can't understand this. Please, anyone, help me to get this.

Osama said:   5 years ago
@All.

Here args take the value from the command line i.e command line arguments from the keyboard.

When you compile the program and runs it using java Test .
Along with java Test you have to give the value for an array also like a[0],a[1],a[2] for a[3] give the int value 2 i.e you're passing the value from keyboard to that method here args is a parameter that expects some value from the user so, java Test 1,3,2,2 will be sent from the user keyboard and store it in an array in args so the value of

a[0]=1
a[1]=3
a[2]=2
a[3]=2 remember that a[0] is already been specified.

Kumar said:   4 years ago
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);
}
}


See here;

Select how you would start the program to cause it to print: *Arg is 2*
We have to print *Arg is 2* and array start with *index 0*
So by option, we need 2 at the index of 3.

args[0] note it is not given in program
args[1]
args[2]
at args[3] we need 2 so by option *java Myfile 1 3 2 2* it is correct.

Maruthu said:   3 years ago
Very confusing, somebody please help me.

Nijin said:   1 decade ago
Can anybody help me understanding this?

Raju said:   1 decade ago
Guys Here question is asked about rip means args[3]. So don't think about args[0], args[1] or args[2]. Only think that in 4th args[] i.e. args[3] comes on which order.

String args[] position
biz = args[1] 0
baz = args[2] 1
rip = args[3] 2

And we can easily say that,

Whatever we will give the sequence no in input the 4th place should be 2nd position and here is only in option.

1 3 2 2

Sindoori said:   1 decade ago
If command line args starts from 0123 then how args[1] is 3 and args[2] is 2. The answer should be 1232.


Post your comments here:

Your comments will be displayed after verification.