richATrichardjones
Technical User
Hi
I have a class called test. When I call test with "java test" I want to give it parameters. For example "javac test.java" to compile it then "java test(2,20)"
I am not sure how to do this. The code so far is
class test{
int one;
int two;
public test(int IPone, int IPtwo)
{
one = IPone; //assing input num to the int one and two
two = IPtwo;
}
public static void main(String[] args){
//make object and pass it parameters
test mytest = new test(IPone, IPtwo);
//show parameters have been assigned (line for debugging)
System.out.println(one);
System.out.println(two);
}
}
This however does not work. I have done it before where I can pass it parameters within some other code. However I want to pass it parameters when I call it when I start the prog like so "java test(20,4)"
Thanks for any help
Richard
I have a class called test. When I call test with "java test" I want to give it parameters. For example "javac test.java" to compile it then "java test(2,20)"
I am not sure how to do this. The code so far is
class test{
int one;
int two;
public test(int IPone, int IPtwo)
{
one = IPone; //assing input num to the int one and two
two = IPtwo;
}
public static void main(String[] args){
//make object and pass it parameters
test mytest = new test(IPone, IPtwo);
//show parameters have been assigned (line for debugging)
System.out.println(one);
System.out.println(two);
}
}
This however does not work. I have done it before where I can pass it parameters within some other code. However I want to pass it parameters when I call it when I start the prog like so "java test(20,4)"
Thanks for any help
Richard