What is the opposite condition of cay plus 1 is less than or equal to sara? Write a condition that’s the opposite of cay plus 1 is less that or equal to sara. So, a condition that’s true when this one is false, and false when this one is true. Do the same for these…

# Tag: methods

## Comments – Intro to Java Programming

There’s one more useful aspect about declaring variables, namely comments. Have a look at this variable declaration, we have a travelTime of 228 days. When you read it you probably ask yourself, for which trip? Now I can tell you for which trip, but when you write code it’s very common that you look at…

## Random Numbers – Intro to Java Programming

A common use for loops is in programs that simulate some activity, such as customers in a supermarket, cars on a road, particles in a physical system. And in such simulations you want to have a degree of randomness, just to model how the real world works. For example, some random time might elapse. Until…

## The First Time Is Special – Intro to Java Programming

Let’s look again at our code for computing the largest value. We duplicate the lines asking the user to enter a value. Can we avoid this special case for entering the value the first time? What if, instead of initializing largest with the first double, we initialize it as 0? Will this work? Yes, it…

## An Interesting Project Ellora Worked On – Intro to Java Programming

So, one of the most interesting projects I’ve worked on was actually a project that arose out of personal interests. This was around the time that the Euro 2012, which is an international soccer competition was happening. And, so what I did is I went on to the Euro website and I took a whole…

## Exactly One Three – Intro to Java Programming

How would you test whether exactly one of them is a 3?

## Finding the First Match – Intro to Java Programming

Let’s return to our Alice in Wonderland example for a minute. What if I want to write a program that finds interesting words that occur in the book? A lot of the time shorter words are more common words. Maybe longer words are more interesting, and more likely to be related to the exact topic…

## Counting Iterations – Intro to Java Programming

If we have 10 sections: one, two, three, four, five, six, seven, eight, nine, ten. Let’s look at the posts: one, two, three, four, five, six, seven, eight, nine, ten. Now, we have one post before every section, and eleven, there’s one after. So the answer was the 11 posts.

## Update the Person Class – Intro to Java Programming

I’m going to step through this answer and narrate my thoughts. So, you can pause my answer at any time and go back and try again if you got stuck somewhere. First, I thought about when I want to draw the line. I want to draw it when I add a friend. So, I’m going…

## Arithmetic Operations 2 – Intro to Java Programming

Now that you’ve seen some of the quirks of math and Java, and why they happen, it’s time to practice writing your own Java expressions for math calculations. We started a class for you that has a method for each of these expressions. Can you fill in the Java code for each of the methods?…