ShmoopTube

Where Monty Python meets your 10th grade teacher.

Search Thousands of Shmoop Videos


AP Computer Science A Videos 108 videos

AP Computer Science 3.5 Classes and Objects
186 Views

AP Computer Science: Classes and Objects Drill 3, Problem 5. Which of the following is not an object?

AP Computer Science 3.4 Classes and Objects
176 Views

AP Computer Science: Classes and Objects Drill 3, Problem 4. Which of the following are objects?

AP Computer Science 4.1 Classes and Objects
174 Views

AP Computer Science 4.1 Classes and Objects. Which of the answers is the best definition of a postcondition?

See All

AP Computer Science 4.5 Standard Algorithms 171 Views


Share It!


Description:

AP Computer Science 4.5 Standard Algorithms. Which of the following implementations successfully copies over array myalph to ArrayList alphabet?

Language:
English Language

Transcript

00:00

Sorry And here's your shmoop du jour brought to you

00:05

by people who can say the alphabet backwards either they're

00:08

extremely smart they know how to reiterate backwards through an

00:11

array or they've just done a lot of sobriety tests

00:14

and you don't want to go there All right Which

00:18

of the following implementation successfully copies over array my alf

00:22

to a realist alphabet All right And here your potential

00:26

answers brought to you by the romans Okay option one

00:33

uses a for each loop which will cycle once for

00:36

each element in an array In this case for each

00:39

string in the array my alf we'll add the content

00:42

of that element to the array list alphabet and the

00:46

loop will in as soon as we've reached the end

00:48

of my al that's about as simple as it gets

00:51

and it will totally work all right Option two option

00:54

two creates an iterated that begins at zero And while

00:58

the current element of my health is not equal to

01:01

z where it'll add that particular value to alphabet add

01:06

one to the generator and do it all over again

01:09

Do that to me one more time Great hold when

01:13

the wild statement finally does find a value equal to

01:16

z it'll end the loop and travel down to the

01:18

next statement adding the current value of my alf meaning

01:22

z we just found the alphabet so option two fits

01:25

the bill to woo hoo wiseguys will have already noticed

01:29

that none of the possible answers are all three options

01:31

work and think we're totally done here but because we're

01:33

also smart and uptight about things we're going to not

01:37

just assume the answer is d all right so let's

01:39

just check out option three and be sure it doesn't

01:41

work looks decent on first glance right Well standard looking

01:45

loop something niggling with the array list Nothing obviously a

01:48

miss Ah wait we can't use that alphabet dot set

01:51

call on indices that don't exist yet remember our ray

01:55

list alphabet is totally empty all set replaces elements that

01:58

already exist with other elements We need to use an

02:01

ad call instead and if we're being nitpicky Well that

02:05

four loop set up is saying well i is less

02:08

than alphabet dot size and that would have to be

02:11

changed to the size of alphabet at this stage would

02:13

be zero so the loop would never run it all

02:16

Changing that terminator parameter too While i is less than

02:20

my health dot length would allow the loop to run

02:22

the full twenty six Anyway we're done Wait okay we're 00:02:27.198 --> [endTime] leaving we're leaving

Related Videos

AP Computer Science 1.4 Standard Algorithms
200 Views

AP Computer Science 1.4 Standard Algorithms. How many times will mystery be called for mystery(n) for n > 1?

AP Computer Science 4.2 Standard Algorithms
191 Views

AP Computer Science 4.2 Standard Algorithms. What kind of algorithm is the following?

AP Computer Science 1.2 GridWorld Case Study and APIs
493 Views

AP Computer Science 1.2 GridWorld Case Study and APIs. What is the direction of the actor?

AP Computer Science 2.3 Classes and Objects
191 Views

AP Computer Science 2.3 Classes and Objects. Which of the following is correct implementation of the Country class?

AP Computer Science 3.4 Inheritance, Abstraction, and Polymorphism
204 Views

AP Computer Science 3.4 Inheritance, Abstraction, and Polymorphism. Which of the following will satisfy the conditional if statement for boo, str,...