how to write an array with a for loop code example
Example 1: arrays with for loops
int findSmallest(int[] values) {
int minIndex = 0; // start with 0th element as min
for (int i=1; i
Example 2: arrays with for loops
// Given an array of booleans representing a series
// of coin tosses (true=heads, false=tails),
// returns true if the array contains anywhere within it
// a string of 10 heads in a row.
// (example of a search loop)
public boolean searchHeads(boolean[] heads) {
int streak = 0; // count the streak of heads in a row
for (int i=0; i