more14
Objective: Write program code to create, traverse, and manipulate elements in 1D array or ArrayList objects.
Given a list of ints, return true if the number of 1's is greater than the number of 4's
more14([1, 4, 1]) -> true
more14([1, 4, 1, 4]) -> false
more14([1, 1]) -> true
If you are only reading values from a list, sometimes it's convenient to use an enhanced for-loop! This syntax works for both arrays and lists.
//General form
for( dataType temp : nameOfList){
}
//Example for a list called myList containing ints.
for(int elements : myList){
}
In the example above, it reads "for every int element in myList". The enhanced for loop will automatically traverse from index 0 to the end! Note that if you want control over your indexing variable then it is not what you want.
The following are methods of a list that can be used to manipulate the contained data.