Here is how I did that. In the outer loop, I just go through all of the people. This inner loop is one of the algorithms that you’ve seen in lesson seven. It’s the algorithm to find something. I keep on iterating over all the cars until I’ve been successful. In each step, I look…

# Tag: methods

## Discovering Instance Variables – Intro to Java Programming

Many lessons ago, we’ve talked about how to develop the public interface of the class, the methods that one might want to call on objects of the class. But we’ve always pretty much given to you the instance variables, because it turns out that picking the right instance variables isn’t all that simple. While now,…

## The Cutest Kitten – Intro to Java Programming

What if I add a line to the bottom of this program? What do you think will happen if I try to compile this code and run it? Will the code compile? Will there be an error? What age of kitten would trigger this return statement? Let’s try it, the code won’t compile. It says…

## Introducing Molly – Intro to Java Programming

My name’s Molly Mackinlay, I’m from Belleview Washington and I’m a senior here at Stanford. And I first got into computer science when I was doing a first robotics program at my high school. I didn’t take any coding classes until I got to Sanford and I took CS106A, my freshman year, fall quarter. And…

## Fix The Pseudocode – Intro to Java Programming

If n is 123, count will end up as 3, which would be correct. There are three digits. If n is 100, count will end up as 2, which is not the correct number of digits. The loop condition should actually be. While temp is greater than or equal to 10. We can see this…

## More Method Descriptions – Intro to Java Programming

How about replace? How many parameters does it have, and what are their types? What is the type of the return value? This last one, print line, isn’t from the stream class, it’s from the print stream class. How many parameters does it have, what’s their type? How many return values does it have?

## First Do It by Hand, Part 2 – Intro to Java Programming

So let’s say we have a width of a hundred inches and each of these tiles is five by five inches. Note that except for the first tile, the others come in pairs. Each pair is ten inches long. So if I take my width, subtract the 5 inches here then I have 95 inches…

## Average of No Inputs – Intro to Java Programming

Now here’s a question. What does the average program print if you immediately type Q when prompted for a value? You may to try this out in BlueJ. Does the program print zero? Does the program terminate with an arithmetic exception? Does it print NaN? Or does it do something else?

## Comparing Decimals – Intro to Java Programming

Okay. When you run this program, you notice that you don’t get the answer there the same. But you get that root squared is a value that’s close to 2, but not quite. So there’s a tiny error in that computation. These errors are unavoidable. Because decimal numbers cannot store an infinite number of digits….

## Practice With Relational Operators – Intro to Java Programming

Cay and I are in a twitter battle. I claimed that I will always have at least one more twitter follower than he has. In other words, my number of twitter followers will always be greater than or equal to the number that Cay has plus one. Is this true, if Cay has three followers…