# Unit 4A - Arrays Code Practice

Each coding exercise has its own folder. Open its `.java` file and press **Run** to try it. **Run Tests** checks every graded exercise in this lesson at once.

## Practice Problems

### Exercise 1

Fix the code so that it prints every other value in the array `arr1` starting with the value at index 0.

> Open the `01-ArraysPractice1` folder and edit `Test1.java`. Press **Run** to try it; **Run Tests** checks it (4 tests).

### Exercise 2

Fix the following to print the values in the array `a1` starting with the value at the last index and then backwards to the value at the first index.

> Open the `02-ArraysPractice2` folder and edit `Test1.java`. Press **Run** to try it; **Run Tests** checks it (4 tests).

### Exercise 3

Rewrite the code so that it prints all the values in an array `arr1` using a for-each loop instead of a `for` loop.

> Open the `03-ArraysPractice3` folder and edit `Test1.java`. Press **Run** to try it; **Run Tests** checks it (2 tests). Its tests check your code, not what it prints: “for each loop”, “print statement variable name”.

### Exercise 4

Finish the code so that it prints out all of the odd values in the array `a1`. Hint: use % to check for odd values.

> Open the `04-ArraysPractice4` folder and edit `Test1.java`. Press **Run** to try it; **Run Tests** checks it (2 tests).

### Exercise 5

Finish the following method `getSum` to return the sum of all values in the passed array.

> Open the `05-ArraysPractice5` folder and edit `Test1.java`. Press **Run** to try it; **Run Tests** checks it (2 tests).

### Exercise 6

Finish the following method to return the sum of all of the non-negative values in the passed array.

> Open the `06-ArraysPractice6` folder and edit `Test1.java`. Press **Run** to try it; **Run Tests** checks it (2 tests).

### Exercise 7

Finish the code to print the strings at the odd indices in the array.

> Open the `07-ArraysPractice7` folder and edit `Test1.java`. Press **Run** to try it; **Run Tests** checks it (2 tests).

### Exercise 8

Finish the method `getSumChars` to return the total number of characters in the array of strings `strArr`.

> Open the `08-ArraysPractice8` folder and edit `Test1.java`. Press **Run** to try it; **Run Tests** checks it (4 tests).

### Exercise 9

Finish the method `findMin` so that it finds and returns the minimum value in the array.

> Open the `09-ArraysPractice9` folder and edit `Test1.java`. Press **Run** to try it; **Run Tests** checks it (3 tests).

### Exercise 10

Finish the method `getAverage` to calculate and return the average of all of the values in the array.

> Open the `10-ArraysPractice10` folder and edit `Test1.java`. Press **Run** to try it; **Run Tests** checks it (3 tests).

## More Practice

For practice with simple array manipulation and conditionals, but no loops see [http://codingbat.com/java/Array-1](http://codingbat.com/java/Array-1). For more practice with loops and arrays go to [http://codingbat.com/java/Array-2](http://codingbat.com/java/Array-2).

Here are problems without loops

- [http://codingbat.com/prob/p167011](http://codingbat.com/prob/p167011)
- [http://codingbat.com/prob/p191991](http://codingbat.com/prob/p191991)
- [http://codingbat.com/prob/p146256](http://codingbat.com/prob/p146256)
- [http://codingbat.com/prob/p199519](http://codingbat.com/prob/p199519)
- [http://codingbat.com/prob/p109537](http://codingbat.com/prob/p109537)

Here are problems with loops

- [http://codingbat.com/prob/p180920](http://codingbat.com/prob/p180920)
- [http://codingbat.com/prob/p104627](http://codingbat.com/prob/p104627)
- [http://codingbat.com/prob/p199612](http://codingbat.com/prob/p199612)
- [http://codingbat.com/prob/p105031](http://codingbat.com/prob/p105031)
- [http://codingbat.com/prob/p100246](http://codingbat.com/prob/p100246)
