Category: Introduction to Java
-
Coding Challenge 8
For the 8th Coding Challenge, we will make a program that has 2 methods. The first method will be a user-made method: static void makeCoffee. This method will also have a parameter: boolean wantsCoffee. Within the user-made method, we will have an if statement that only executes when wantsCoffee is true. The if statement (when…
-
Lesson 31: Method Parameters and Arguments
When working with methods, there will be times that we want to keep variables only within our method. Java has a way of doing this through the usage of parameters. Parameters are declared within the parenthesis of our method. Let’s go over an example of a method with parameters. In the example above, we have…
-
Lesson 30: Methods
Methods are one of the fundamentals of programming. As you might recall from our object-oriented programming lesson, we talked about how classes are typically nouns and methods are verbs. They help reduce redundancy by being able to use them an unlimited amount of times throughout our code for different instances. Thus far, we have been…
-
Lesson 29: Logical Operators
Thus far, we have gone over various operators that we have been using to create our Boolean expressions. However, we have been limited by only using one Boolean expression at time. In this lesson, we will take a look at logical operators. In Java, there are 3 logical operators: Symbol Meaning Code AND && OR…
-
Lesson 28: Escape Sequences
In past lessons, we have gone over a couple of different ways we can manipulate Strings. We have learned about various print methods and adding spaces with quotation marks to get our desired output. In this lesson, we are going to go over escape sequences that can help simplify some of our string manipulation, as…
-
Coding Challenge 7
For the 7th coding challenge, we will make a program that contains a for loop and 2 int variables. The program’s purpose will be to act as a countdown timer for NASA. We want the countdown to start at 10 and finish at 1. Feel free to name the variables on your own. However, be…
-
Lesson 27: The Modulus Operator
In some of the earlier lessons, we went over the 4 most used math operators used in Java. Those four included: Addition + Subtraction – Multiplication * Division / Now that we have a little practice underneath our belt in Java, we are going to introduce a new math operator that you’ve probably never seen. …
-
Lesson 26: println() vs print()
In the previous lesson, we went over a program that counted to the number 10 using a for loop. Using the System.out.println() method, every loop printed the number on a new line. However, what if we wanted to print our numbers out on one line? So far, we have only used the print method System.out.println()…
-
Lesson 25: For Loops
In earlier lessons we went over while and do while loops and learned in what cases we would use them. In this lesson, we will be going over a new loop called a for loop. For loops typically serve a much more specific role, than other loops. Let’s look over the outline of one: There…