IndiaBIX.com
Arithmetic Aptitude Data Interpretation
Logical Reasoning Verbal Reasoning Non Verbal Reasoning
General Knowledge
Sudoku Number puzzles Missing letters puzzles Logical puzzles Playing cards puzzles Clock puzzles
C Programming C++ Programming C# Programming Java Programming
Microbiology Biochemistry Biotechnology Biochemical Engineering
Civil Engineering Mechanical Engineering Chemical Engineering Networking Database Questions Computer Science Basic Electronics Digital Electronics Electronic Devices Circuit Simulation Electrical Enigneering Engineering Mechanics Technical Drawing
Placement Papers Group Disucssion HR Interview Technical Interview Body Language
Aptitude Test Verbal Ability Test Verbal Reasoning Test Logical Reasoning Test C Programming Test Java Programming Test Data Interpretation Test General Knowledge Test
Data Structures Operating Systems Networking DATABASE Database Basics SQL Server Basics SQL Server Advanced SQL Server 2008 JAVA Core Java Java Basics Advanced Java UNIX Unix File Management Unix Memory Management Unix Process Managemnt C Interview Questions The C Language Basics .NET Interview Questions .NET Framework ADO.NET ASP.NET Software Testing

Java Programming - Java.lang Class - Discussion

@ : Home > Java Programming > Java.lang Class > General Questions - Discussion

Read more:

"Weakness of attitude becomes weakness of character."
- Albert Einstein
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

[A]. java Myfile 222
[B]. java Myfile 1 2 2 3 4
[C]. java Myfile 1 3 2 2
[D]. java Myfile 0 1 2 3

Answer: Option B

Explanation:

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


Nijin said: (Fri, Feb 25, 2011 02:10:53 AM)    
 
Can anybody help me understanding this?

Sathish said: (Wed, Jun 1, 2011 01:58:59 PM)    
 
I can't understanding this concept please any one help me.

Abhijit said: (Fri, Jun 17, 2011 10:56:39 AM)    
 
args[0]=1,args[1]=3,args[2]=2,args[3]=3 and hence rip=args[3]=3

Akash Gupta said: (Sat, Aug 27, 2011 05:55:20 PM)    
 
This is very cconfusinig,i can't satisfied with your sugesition.

Sreekanth said: (Tue, Aug 30, 2011 03:41:32 PM)    
 
Actually if you check here as explained by args[0] = java args[1] = Myfile args[2] = 1 and args[3] = 3.

So the answer is not a correct one.

Sundar said: (Thu, Sep 22, 2011 06:25:34 PM)    
 
The given answer is correct. I have tested the same.

D:\Siva\Java>type Test.java
public class Test
{
public static void main (String[] args)
{
String biz = args[1];
String baz = args[2];
String rip = args[3];
System.out.println("Arg is " + rip);
}
}
D:\Siva\Java>javac Test.java

D:\Siva\Java>java Test 1 3 2 2
Arg is 2

D:\Siva\Java>


Hope this will help you. Have a nice day!

Asoka said: (Tue, Jan 10, 2012 09:08:06 PM)    
 
I think [B] is correct answer!
The same with Sundar!

Arindam said: (Wed, Feb 1, 2012 08:24:44 AM)    
 
When we want to run a java program then we always use
"java main_class_name"

But you use something more then that are stored in args[] array, which is also known as command line argument....

For ex- i write "java main_class_name Arindam Ghosh"
then program will run but 'Arindam' will stored in args[0] and 'Ghosh' will stored in args[1];

That's why here rip=args[3]=2

args[0]=1
args[1]=3
args[2]=2
args[3]=2

Subhan said: (Fri, Aug 17, 2012 04:29:09 PM)    
 
Anybody can explain this code clearly please I can't understand

Anvesh said: (Wed, Nov 21, 2012 03:01:47 PM)    
 
Yes dude,actually this is command line args, so normally arrays will be starting with zero, so given that answer c is correct, how means

args[1]=0;
args[2]=1;
args[3]=2;

So this args[3] value will be coming with we are using command line args. First you learn command line args carefully.

Write your comments here:
Name *:     Email:


© 2008-2013 by IndiaBIX™ Technologies. All Rights Reserved | Copyright | Terms of Use & Privacy Policy

Contact us: info@indiabix.com     Follow us on twitter!