Evaluate Code Segments that Iterate Over an ArrayList
Need Help? Check out these resources!
- Learn: Constructing an ArrayList Object
- Learn: Adding Values to an ArrayList Object
- Learn: Accessing and Removing Values from an ArrayList Object
- Learn: Changing Values in an ArrayList Object
- Learn: Analyzing an ArrayList Object
- Learn: Iterating Over an ArrayList Object
Evaluating Expressions
|
Grab a Piece of Paper! |
Evaluate each expression. Verify your answer by running the code in the Java Playground. |
Practice 1: Animal List
- Trace the provide code segment and predict the output.
- Verify your prediction is correct by running the code in the Java Playground.
- Modify the code segment to print the name of each animal. Run the code to test.
- Modify the code to change the names of the animals to be all uppercase. Run the code to test.
Practice 2: XYZ Practice
- Trace the provide code segment and predict the output.
- Verify your prediction is correct by running the code in the Java Playground.
Practice 3: Sum the Values
- Trace the provide code segment and predict the output.
- Verify your prediction is correct by running the code in the Java Playground.
- Modify the code to print a running total as each value is added to sum. It should print 2.5 and then 6.5 and then 12. Run your code to test.
Practice 4: Reverse Order
- Trace the provide code segment and predict the output.
- Verify your prediction is correct by running the code in the Java Playground.
Practice 5: Update Numbers
- Trace the provide code segment and predict the output.
- Verify your prediction is correct by running the code in the Java Playground.
Practice 6: Even or Odd
- Trace the provide code segment and predict the output.
- Verify your prediction is correct by running the code in the Java Playground.
- Modify the code so that only odd values are printed. Verify your code is correct by running it.