only14
Objective: Write program code to create, traverse, and manipulate elements in 1D array or ArrayList objects.

Given a list of ints, return true if every element is a 1 or a 4.

only14([1, 4, 1, 4])  -> true
only14([1, 4, 2, 4])  -> false
only14([1, 1])  ->true


Below is the typical regular for-loop setup as well as the enhanced for-loop setup. 
How do you get the size of an ArrayList? How is it different from arrays and Strings?

for(int i = 0; i < nums.size(); i++){
   //loop generates all the valid indexes starting at 0
}

//Sometimes if you're mostly concerned about reading values
//an enhanced for-loop can be a more elegant solution
for(int el : nums){
   //this loop automatically visits every element
   //starting at position 0. each iteration, el is set to
   //the element at the current position. for example,
   //in iteration 0, el will be the element at pos 0.

}
The following are methods of a list that can be used to manipulate the contained data.


Type your solution        
Skills Practiced:
3.C
3.D
4.A
4.B
Copyright © StudyCS 2024 All rights reserved.