Alright, so I'm supposed to work with this as the beginning of my code:
public static int addOdds(int[] input){}
That would return the sum.
I have the add odds part finished with pre loaded arrays. That was simple enough, but what is flustering my person is how to get this to take an array as input from user.
I know of Scanner from java.utils, but I'm not sure how to get it to run with my code to make it take an array (if it can).
I considered using:
public string void main(String [] args){}
And call Scanner with it, and use Integer.parseint(), but I don't think that could parse an array.
Then call the input the array from scanner to be handed off to the addOdds method.
An example would be {2,3,7,8,4,1} would be what the code must take as input.
Thanks in advance, I'm a bit stumped.
If it helps, here is an example query; inputTwo isn't relevant to the question:
public class Proj2Tester {
public static void main(String[] args){
int[] inputOne = {4,8,9,12,7};
int[] inputTwo = {41,38,19,112,705};
System.out.println("Problem 1 is correct on test input = " + (16 == Problem1.addOdds(inputOne)));
System.out.println("Problem 2 is correct on test input = " + (686== Problem2.getRange(inputTwo)));
}
Following T.J.'s advice I tried the following:
public class Problem1 { public static void main(String args[]){
System.out.println("Your array is: "+input);
}
}
public static int addOdds(int[] input){
int[] input = new int[args.length]; //Begin T.J.'s segment
int n = 0;
for (String arg : args) {
input[n++] = Integer.parseInt(arg);
int sum =0; //Initializing sum as 0;
for(int i =0; i < inputOne.length; i++){
if(inputOne[i] % 2 !=0){
;
sum = sum + inputOne[i];
break;
}
if(inputOne[i] % 2 == 0){
i++;
break;
}
}
return sum; // placeholder for my answer, not zero should be returned
}