Page 1 of 1

public class ArraysLab { public static void main(String[] args) { System.out.println("\n === PART 1 ===

Posted: Sun Jul 10, 2022 11:23 am
by answerhappygod
public class ArraysLab{ public static void main(String[] args) { System.out.println("\n ===PART 1 === \n"); /* Create an an array withthe following values and print the valuesout one at a time using a for loop: 1, 7, 4, 6, 5, 5, 3 */
System.out.println("\n ===PART 2 === \n"); /* Make a copy of your loopfrom part 1, but modify it to print thefollowing: The valueat index 0 is 1 The valueat index 1 is 7 The valueat index 2 is 4 The valueat index 3 is 6 The valueat index 4 is 5 The valueat index 5 is 5 The valueat index 6 is 3 */
System.out.println("\n ===PART 3 === \n"); /* Create another copy of theprevious loop and modify it slightlyto print out the indexes starting at 1,like so: The valueat index 1 is 1 The valueat index 2 is 7 The valueat index 3 is 4 The valueat index 4 is 6 The valueat index 5 is 5 The valueat index 6 is 5 The valueat index 7 is 3 */
System.out.println("\n ===PART 4 === \n"); /* Write a single line ofcode that prints out 6 by indexing intothe array from part 1. */
System.out.println("\n ===PART 5 === \n"); /* Uncomment the followingthen fill in the blanks to complete aprogram that counts up the values in thearray that are greater than 4. */ /* int values[] ={5,9,3,7,2,6}; int count = ___; for(int i=0;___<values.length; i++) { if(values[___] > 4) { count = ___; } } System.out.println(count+"values in the array are greater than 4"); */
System.out.println("\n ===PART 6 === \n"); /* Uncomment the followingthen fill in the blanks to complete aprogram that sums up the values in the arraythat are greater than the first value in thearray. You must use indexing to access thefirst value in the array. */ /* int numbers[] ={6,8,1,5,9,3,7,2,6}; int total = ___; for(int i=0;___<numbers.length; i++) { if(numbers[___] > ___) { total += ___; } } System.out.println(total+" isthe sum of values in the array greater than the first value");//The correct answer is 8+9+7=24 */
System.out.println("\n ===PART 7 === \n"); /* Make a copy of theprevious program, but modify it so that it sumsup the indexes of the values thatare greater than the first value. Inother words, since 8 is at index 1, 9 isat index 4, and 7 is at index 6, theprogram should add up 1+4+6 = 11 */