Explore what CodeHS has to offer for districts, schools, and teachers.
Click on one of our programs below to get started coding in the sandbox!
View All
Assuming the following arrays are declared, which code snippet will print out only odd numbers?
int[] array1 = {1, 3, 7, 8, 9}; int[] array2 = {2, 4, 6, 8, 10}; int[] array3 = {1, 2, 3, 4, 5, 6, 7};
for(int num : array1) { System.out.println(num); }
for(int num : array2) { System.out.println(num); }
for(int num : array3) { System.out.println(num); }
System.out.println(array1[0]); System.out.println(array1[3]); System.out.println(array3[2]);
System.out.println(array1[0]); System.out.println(array1[2]); System.out.println(array3[4]);