created 11/25/2021

# Chapter 32 Programming Exercises

## Exercise 1 — Largest Positive Odd in a List

Write a program that asks the user for 10 positive integers and then prints out the largest odd integer of them. If no odd integer was entered, print out a message that says so. The integers can be entered in any order and may be repeated.

Odd integers may be detected using the % operator with 2. See Chapter 10 page 14 and following.

```C:\>java LargeOdd
Enter integer 1: 2
Enter integer 2: 3
Enter integer 3: 4
Enter integer 4: 2
Enter integer 5: 8
Enter integer 6: 22
Enter integer 7: 9
Enter integer 8: 3
Enter integer 9: 1
Enter integer 10: 46
The largest odd integer was 9
C:\>
```

Hint: Use a variable for the current integer, for the best so far, and a boolean variable that indicates if a candidate has been found.

## Exercise 2 — Largest Positive or Negative Odd in a List

Write a program that asks the user for 10 integers, which may be positive, negative, or zero and then prints out the largest odd integer of them. If no odd integer was entered, print out a message that says so. The integers can be entered in any order and may be repeated.

The % operator returns a 0 or negative value. You will need to add to the logic of the previous program, or use `Math.abs()`.

```C:\>java LargeOdd
Enter integer 1: 0
Enter integer 2: -7
Enter integer 3: -31
Enter integer 4: 2
Enter integer 5: 4
Enter integer 6: 6
Enter integer 7: 0
Enter integer 8: -8
Enter integer 9: -3
Enter integer 10: 6
The largest odd integer was -3
C:\>
```

Hint: Use a variable for the current integer, for the best so far, and a boolean variable that indicates if a candidate has been found.