?
Solved

run time parameters

Posted on 2002-03-19
11
Medium Priority
?
178 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
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
 
LVL 9

Accepted Solution

by:
yongsing earned 200 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.
Suggested Courses
Course of the Month13 days, 3 hours left to enroll

777 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