Java Basics 4 - First Coding Exercise Solution

Words
308
Reading
2 min
Listen
Play
8y

Thumbnail

Lecture 4: First Coding Exercise Solution

First Coding Exercise


Write a statement to print the text, ‘Hi there’ in Java.

irst Coding Solution


System.out.print("Hi, there");

public class Lecture4 {
public static void main(String[] args) {
// TODO: Write a statement to print the text, ‘Hi there’
}
}

First Coding Output


Hi, there**


Hi there, This is Marius from AlefTav Coding. In today's lecture you will learn the solution to the first coding exercise.

Your homework was, Write a statement to print the text, ‘Hi there’ in Java. I gave you starting code with the class as Lecture4, the main() method, and a TODO comment. You were asked to write your solution code at the line where the TODO comment appears.

You use the print() statement in Java to inspect if your code works as expected. The format of this statement is, System.out.print(). The word, System is a Java class, therefore it starts with a capital letter, S. The words, out and print are all small letters.

print() is a Java method. So, it should be followed by 2 round brackets, (). Inside these brackets is where you type the text that must be displayed. Also, this text must appear between a set of quotation marksm "". Finally, to end this statement you need a semi-colon (;).

When this code is executed, the words, hi, there are displayed on your computer screen.

Please note that your code needs to be exactly like this for it to work.


In this lecture you learnt the solution to the first coding exercise. In the next lecture I will look at Java's *Primitive* data types.

I am Marius from AlefTav Coding. Until the next lecture, KEEP CODING.

If you found this tutorial helpful, please upvote, subscribe, like and share. You can find me at the following links.

https://busy.org/@mariusclaassen
https://steemit.com/@mariusclaassen
https://d.tube/#!/c/mariusclaassen
https://bit.tube/mariusclaassen

My video is at DLive

Java Basics 4 - First Coding Exercise Solution | Ecency