Solved

run time parameters

Posted on 2002-03-19
11
176 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
eclipse apache tomcat admin console 52 156
jmss example java 2 33
printf performancy 11 86
junit example issue 2 28
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
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 will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
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:

726 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