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 2Answer: Option
Explanation:
Arguments start at array element 0 so the fourth arguement must be 2 to produce the correct output.
Discussion:
33 comments Page 4 of 4.
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.
{
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.
Shuvo said:
3 years ago
public class Test1
{
public static void main (String[] args)
{
String biz = args[1];
String baz = args[2];
String rip = args[3];
System.out.println("Arg is " + rip);
}
}
run through terminal:
> javac Test1.java
> java Test1 java Myfile 1 2 2 3 4
Arg is 2.
So, option B will be right.
{
public static void main (String[] args)
{
String biz = args[1];
String baz = args[2];
String rip = args[3];
System.out.println("Arg is " + rip);
}
}
run through terminal:
> javac Test1.java
> java Test1 java Myfile 1 2 2 3 4
Arg is 2.
So, option B will be right.
(1)
Maruthu said:
3 years ago
Very confusing, somebody please help me.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers