I'm using eclipse to build a java package. I'm getting an error for numbers[i] = Integer.parseInt(args[i]); I don't know what I'm doing wrong. Thanks! import java.util.Arrays; public class TestForSumInts { public static int sumInts(int[] arr) { int sum = 0; for (int i = 0; i < arr.length; i++) { sum += arr[i]; } return sum; } public static void main(String[] args) { if (args.length==0) { System.out.println("numbers were not provided as Command line arguments"); } else { int[] numbers = new int[args.length]; for (int i = 0; i < numbers.length; i++) { numbers[i] = Integer.parseInt(args[i]); } System.out.println("Passing " + Arrays.toString(numbers)); System.out.println("Sum is " + sumInts(numbers)); } } }
I'm using eclipse to build a java package. I'm getting an error for
numbers[i] = Integer.parseInt(args[i]);
I don't know what I'm doing wrong. Thanks!
import java.util.Arrays;
public class TestForSumInts {
public static int sumInts(int[] arr) {
int sum = 0;
for (int i = 0; i < arr.length; i++) {
sum += arr[i];
}
return sum;
}
public static void main(String[] args) {
if (args.length==0) {
System.out.println("numbers were not provided as Command line arguments");
} else {
int[] numbers = new int[args.length];
for (int i = 0; i < numbers.length; i++) {
numbers[i] = Integer.parseInt(args[i]);
}
System.out.println("Passing " + Arrays.toString(numbers));
System.out.println("Sum is " + sumInts(numbers));
}
}
}
Trending now
This is a popular solution!
Step by step
Solved in 2 steps with 2 images
In the eclipse
I did a run configuration in the tool and put the 10 20 30 in the arguments section, but because it is saying integer cannot be resolved, it won't run it for me