Solved

run time parameters

Posted on 2002-03-19
11
173 Views
Last Modified: 2010-03-31
what is run time parameter

and how to get system.out.println(arg[o]);

plz waiting for ur help..
0
Comment
Question by:ms_lost
  • 4
  • 4
  • 2
  • +1
11 Comments
 
LVL 18

Expert Comment

by:bobbit31
ID: 6881166
a run-time parameter is a parameter you pass at run-time ;)
(ie. java <Your Class> <p1> <p2>)

> and how to get system.out.println(arg[o]);

public static void main (String[] args) {
   // this will loop through all the parameters passed in and print them to System.out
   for (int i=0;i<args.length;i++) {
       System.out.println(args[i]);
   }
}
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 6881171
Also,

> system.out.println(arg[o]);

should be System.out.println(arg[0]); // a zero not a o
0
 

Author Comment

by:ms_lost
ID: 6881267
it didn't show me anything..
what is the expected out put here..
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 6881290
can you post some code on what you are trying to do?
0
 

Author Comment

by:ms_lost
ID: 6881304
this is only what i've done..i'm trying to understand what is this.. i wrote what u've given to me

public class para
{

public static void main (String[] args)

{
     System.out.println("hello");

//this will loop through all the parameters passed in and print them to System.out
                       for (int i=0;i<args.length;i++)
                       {
                           System.out.println(args[0]);
                       }

                     }
                     }

i can't see anything just the word hello..so what does that args thing do here..
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 9

Accepted Solution

by:
yongsing earned 50 total points
ID: 6881602
"args" is the array of parameters you pass to your program. Run your program again, like this:

java para 1

You will see the output:

hello
1

The word "hello" is printed by calling System.out.println("hello"). The "1" is printed by calling System.out.println(args[0]). "args[0]" refers to the first parameter after your program name, which is "para".

Now change your code to this:

for (int i=0;i<args.length;i++)
{
   System.out.println(args[i]);
}

And run the program:

java para 1 2 3 4

This time you will get:

hello
1
2
3
4

Now you get it?
0
 

Author Comment

by:ms_lost
ID: 6881944
i got the idea..but it's not showing the numbers..just the word hello.. i did it exactly the same.. waiitng for ur help
0
 
LVL 4

Expert Comment

by:Neutron
ID: 6882250
hi ms_lost,

In the code you've posted last:

public class para
{

    public static void main (String[] args)
    {
        System.out.println("hello");
       
        //this will loop through all the parameters passed in and print them to System.out
        for (int i=0;i<args.length;i++)
        {
            System.out.println(args[0]);
        }

    }
}

...you should also correct line
            System.out.println(args[0]);
...so it looks like
            System.out.println(args[i]);
...just like bobbit31 and yongsing said (in order of appearance)

Good luck,
    </ntr> :)
0
 

Author Comment

by:ms_lost
ID: 6883735
i did that ..but i am not getting the 1 2 3 4 out put.. only the world Hello
plzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz check it for me.. i'm waiting from last night for it..
0
 
LVL 18

Expert Comment

by:bobbit31
ID: 6883752
> i did that

you did:

java para 1 2 3 4

and it didn't output
hello
1
2
3
4

???????

0
 
LVL 4

Expert Comment

by:Neutron
ID: 6884961
ms_lost, you know that you should recompile the source every time you modify it :-)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

943 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now