about | help | code help+videos | done | prefs |
jgreenawalt@ccboe.com kjell46andahalf
Description:Array Storage and Retrieval using Logical Operators
The following problems are all from the Stanford site. These problems are intended as practice and to serve as notes for future problems.
rotateLeft3 |
sum3 |
commonEnd |
makePi |
sameFirstLast H |
firstLast6 H
The major new idea in this set of problems is to use logical operators with array values.
The word "and" in English is && in Java.The word "or" in English is || in Java.
For instance, to determine if the second element of an array of ints named nums and the second to last element are both 5 use an if statement containing a boolean expression as like the one below.
if ( nums[1] == 5 && nums[nums.length-2] == 5 ){
// statements to execute if both are 5
}else{
// statements to execute if both are not 5 }
Foreshadowing:Less than and greater than expressions in Java often must combine with an && or || operators. The three part composite comparison common in algebra is not implemented in Java.
Consider the following. The expression "13 <= nums[2] <= 19" in Algebra is 13 <= nums[2] && nums[2] <= 19 in Java.
The next problem set uses loops to access all the values in arrays of unknown size.
teensOnly H |
someTeen H
Authoring docs
Copyright Nick Parlante 2017 - privacy