Hey everyone.
I was doing a simple test program today that my professor is asking us to do just to test to see if his Ant script works correctly and I came across a problem that is confusing me. My prof wants us (after created all of our homework class files) to create a TestProgram class where, basically like junit, tests our programs with his given input values. Well, I have never worked with args before (I know, depressing) but I gave it a ashot and got this error.
TestProgram.java:16: main(java.lang.String[]) in Sum cannot be applied to (java.lang.String)
program.main(arg[0]);
^
TestProgram.java:17: main(java.lang.String[]) in Sum cannot be applied to (java.lang.String)
program.main(arg[1]);
^
TestProgram.java:18: main(java.lang.String[]) in Sum cannot be applied to (java.lang.String)
program.main(arg[2]);
^
TestProgram.java:19: main(java.lang.String[]) in Sum cannot be applied to (java.lang.String)
program.main(arg[3]);
^
Obviously I know exactly what the error is — applying a String array to a String. But I don't see where I am exactly doing that.
Here are my two files:
TestProgram.java
public class TestProgram {
public static void main(String[] args) {
// Sum.java Test
{
Sum program = new Sum();
System.out.println("\n" + "Start Sum Test by Matthew Porter");
String [] arg = new String[4];
arg[0]="5";
arg[1]="7";
arg[2]="10";
arg[3]="12";
program.main(arg[0]);
program.main(arg[1]);
program.main(arg[2]);
program.main(arg[3]);
System.out.println("End of Craps Test" + "\n");
}
}
}
Sum.java
public class Sum {
public static void main (String[] args) {
int sumStop = Integer.parseInt(args[0]);
int sum = 0;
for (int i=1; i<=sumStop; i++) {
sum = sum + i;
}
System.out.println("Sum: " + sum);
}
}
Would anyone be so kind to hint at what I am doing wrong?