Write Java code that creates an array of primitive integers named odds and stores all odd numbers between -6 and 38 using a for loop. (Your code will populate the array.) Your code should also enable the array’s size to be exactly large enough to store the numbers. (You will not put a number for the size, your code will determine the number.) (5 pt)
public class TestCode { public static void main(String[] args) { int odds[] = new int[22]; int k = 0; for(int i = -5;i<38;i+=2){ odds[k++] = i; } for(int i = 0;i<odds.length;i++){ System.out.print(odds[i]+" "); } } }
-5 -3 -1 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37
Get Answers For Free
Most questions answered within 1 hours.