Read chapter 7, sections 7.4 - 7.6, 7.8
int [] sample=new int[8]; int i, k; Using the declarations above, show the array after the following statements: for (k=0; k<8; k++) if (k % 2 == 0) sample[k] = k; else sample[k] = k + 100;
Write the statements to add up those elements of an array of ints (of size 25) which have an even subscript.
Write the statements to add up those elements of an array of ints (of size 25) which have an even value.
What will the following program segment print? int nums = new int[10]; int i; for (i = 9 ; i >= 0 ; i--) { nums[i] = 5 * (i + 1); System.out.print(nums[i] + " "); } System.out.println(); for (i = 0 ; i < 10 ; i++) System.out.print(nums[i] + " "); System.out.println(); for (i = 8 ; i >= 0 ; i--) nums[i+1] = nums[i]; for (i = 0 ; i < 10 ; i++) System.out.print(nums[i] + " "); System.out.println();
Email Me |
Office Hours |
My Home Page |
Department Home |
MCC Home Page
© Copyright Emmi Schatz 2013