package javaapplication1;
/**
*
* @author
*/
public class JavaApplication1 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int[] scores = {1,2,3,4,5,6};
int[] fin = extractAllEvens(scores);
for(int i =0; i<fin.length; i++) {
System.out.println(fin[i]);
}
}
public static int[] extractAllEvens(int[]scores) {
int evenCount = 0;
for (int i =0; i<scores.length; i++) {
if (scores[i] % 2 ==0) {
evenCount++;
}
}
int[] newScores = new int[evenCount];
int j = 0;
for(int i = 0; i<scores.length; i++) {
if(scores[1] % 2 ==0) {
newScores[1] = scores[i];
j++;
}
}
return newScores;
}
}
I'm trying to output 2, 4, 6.
But I keep getting results such as 0,6,0.
I think I messed up somewhere with the variables with i or j or the number 1 and possibly their locations... can anyone help lead me in the right direction?