Solved

run time parameters

Posted on 2002-03-19
11
177 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
The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

 
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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

707 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