Java for Beginners 5 - First Coding Solution

Words
358
Reading
2 min
Listen
Play
8y

Lecture 5: First Coding Solution


First coding exercise

Replace the 'TODO' comment with a statement to print the name, 'Adam'
public class Lecture5 {
    public static void main(String[] args) {
        // TODO: Replace this comment with a statement to print the name, ‘Adam’
    }
}

First coding solution


System.out.print("Adam");

First coding excercise output


Adam


L05 - First Coding Exercise cover cropped.png

Hi there again, this is Marius from AlefTav Coding with Lecture 5 of my course, Java for Beginners. In this lecture I will show you the solution of the first coding exercise.

public class Lecture5 {
    public static void main(String[] args) {
        // TODO: Replace this comment with a statement to print the name, ‘Adam’
    }
}

I have here a one-line comment. Two forward slashes (//) indicate a one-line comment in Java. Anything typed after them in a line is ignored by Java.

In the last lecture, we looked at how to print the two words, hello world. Your homework was the first coding exercise, //TODO: Replace this comment with a statement to print the name, 'Adam'.

I have here a class, which I named, Lecture5 and a method, main().

The first requirement is to do a print statement. In Java the statement to print is, System.out.print. The word, print in Java is a method. Being a method it must be followed by two round braces "( )". Then, the final requirement is to print the word, Adam. In Java, to print text you must put that text between quotation marks, like this, "Adam". Lastly, to end a Java statement you must add a semi-colon (;).

To ensure that my program is correct, I check for the green tick mark at the top-right of my computer screen. Now, when I run this program the word, Adam appears in the output window at the bottom of my screen.

In this lecture we looked at how to solve the first coding exercise. The format of the excercises that follow will be similar to this one.

My name is Marius from AlefTav Coding. Till next time, KEEP CODING.


Please upvote, subscribe, like and share. For more of this you can find me at the following links.

https://busy.org/@mariusclaassen
https://steemit.com/@mariusclaassen
https://d.tube/#!/c/mariusclaassen
https://www.udemy.com/java-8-for-complete-beginners/learn/v4/overview

Java for Beginners 5 - First Coding Solution | Ecency