Programming > STUDY GUIDE > Unit 4: lesson 3; Loops and Strings (All)
Evaluate the following code segments and determine what the output would be when the segment were executed. If an error exists in the code segment, indicate with “error” and describe the reason ... for the error. 1. String word = "Wingardium Leviosa"; for(int x = 0; x<word.length(); x+=2) System.out.print( word.substring(x,x+1)); Answer: ______________________ 2. String word = "Expelliarmus"; for(int x = 0; x<=word.length(); x--) System.out.print( word.substring(x,x+1)); Answer: ______________________ 3. String word = "Alohomora"; for(int x = word.length()- 1; x >= 0; x--) System.out.print( word.substring(x,x+1)); Answer: ______________________ 4. String word = "Expecto Patronum"; String build = ""; for(int x = 0; x < word.length(); x++) { String let = word.substring(x,x+1); if (x % 2 == 1) build = build + let; } [Show More]
Last updated: 2 years ago
Preview 1 out of 2 pages
Buy this document to get the full access instantly
Instant Download Access after purchase
Buy NowInstant download
We Accept:
Can't find what you want? Try our AI powered Search
Connected school, study & course
About the document
Uploaded On
Feb 08, 2023
Number of pages
2
Written in
All
This document has been written for:
Uploaded
Feb 08, 2023
Downloads
0
Views
179
Scholarfriends.com Online Platform by Browsegrades Inc. 651N South Broad St, Middletown DE. United States.
We're available through e-mail, Twitter, Facebook, and live chat.
FAQ
Questions? Leave a message!
Copyright © Scholarfriends · High quality services·