-
Array Odds and Evens
Create an array of 10 integers. Write a program print all the odd numbers then, on a new line, print out the number of even numbers.
Steps
I'm a newb, and getting stuck on how to properly print out the odds and count the evens. So far I'm getting it to print the odds in a list, but then it's just printing everything else after?
public class ArrayProblem{
public static void main(String[] args){
int [] newArray = {9,45,11,2,4,6,8,10,12,14};
System.out.println("The odd numbers are :");
for(int i=0;i<newArray.length;i++){
if(newArray[i]/2 != 0){
System.out.println(newArray[i]);
}
else{
}
}
}
}
-
Re: Array Odds and Evens
Clearly you need to add some code to the else part. The if handles the odd numbers. So what should the else do?
-
Re: Array Odds and Evens