Solved

run time parameters

Posted on 2002-03-19
11
172 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
Comment Utility
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
Comment Utility
Also,

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

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

Author Comment

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

Expert Comment

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

Author Comment

by:ms_lost
Comment Utility
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
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 
LVL 9

Accepted Solution

by:
yongsing earned 50 total points
Comment Utility
"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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
> 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
Comment Utility
ms_lost, you know that you should recompile the source every time you modify it :-)
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
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…
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…
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

743 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

17 Experts available now in Live!

Get 1:1 Help Now