Java for Beginners 9 - Primitive Types: Initialization Solution

Words
265
Reading
2 min
Listen
Play
8y

Lecture 9: Primitive Types: Initialization Solution


Primitive type initalization problem statement

Initialize a 'char' data type named ‘letterY’ with the value ‘Y’

Primitive types initialization coding solution


char letterY = 'Y';

public class Lecture9 {
    public static void main(String[] args) {
        // TODO: Initialize a char data type named ‘letterY’ with the value ‘Y’
        System.out.print(letterY);
    }
}

Primitive Types initialization coding output


Y


L09 - Primitive Data Types Initialization Coding cover.png

Hallo again, I am Marius from AlefTav Coding. In this lecture you will learn the solution to the initializaion coding exercise.

L09 - Primitive Data Types Initialization Coding Exercise cropped.png

The coding exercise required you to Initialize a char data type named ‘letterY’ with the value ‘Y’. Please note it is an uppercase letter, Y. Looking at our expected solution, you use the Java pattern, dataType storageName = value. The problem statement says the data type must be char. Then, the storage name must be, letterY. Finally, the value you need to store is the single character, Y. This letter must be between single quotes, because that is how Java recognizes that a value is of data type char.

L09 - Primitive Data Types Initialization Coding idea for blog.png

The solution code is this line, char letterY = 'Y'. I have here a class, Lecture9 with the usual main() method. This is after I have removed the TODO comment. As always, the semi-colon (;) ends a Java statement.

In this lecture you learned the solution to the initializaion coding exercise.

Next time we will look at using operators in Java.

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


Please be reminded to upvote, re-steem 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 9 - Primitive Types: Initialization Solution | Ecency