Java Tutorial [#03] - Escape Sequences and better print instructions

in #programming7 years ago (edited)

Header.jpg

Disclaimer!
If you find any mistakes in this post or you don't know what to do at a specific point? Feel free to write me a comment! 👍
Greets from Germany ✌️

Last Part Next part
<- #02 Variables and Arithmetic Operators #04 All Loops + more Math ->

1. Advanced printing


Now we have reached the point, we know how to create variables and calculate with them. But how you want to print a line like this?

Image 1.PNG

With our current knowledge, it could look like this:

Image 2.PNG

Mmmmh... please.... don't do this this way. There is an easier method for this. You can place after the text or the variable a + (PLUS) or a & (AND) to connect it with an another text or a variable. This could look like this (In my example I used + (PLUS))

Image 3.PNG

Note: Did you see, how I made a cast at the end around x and y? This means that Java has to calculate it together and then put it to the text.

2. Escape sequences


This is quite important to know. And this is quite more interesting together with the so called "Escape Sequences". This basically means, you can start a new line or tab in the same print instruction.

Here is a table, so it is easier to understand:

Escape Sequence What it does
\t
Insert a tab
\n
New line
\'
Print a normal '
\"
Print a normal "
\\
Print a normal \

In this example I will exaggerate a bit, so please sit down a bit and really try to understand what stands there on this image (This is also really important learning a programming language, to understand the code or just the "logical" thinking):

Image 4.PNG

This code will output this here:

Image 5.PNG

That was all I wanted to say to you. The next part I will write about loops and create some difficult tasks you have to challenge with.

Support this project by upvote this post and commenting ^^

Last Part Next part
<- #02 Variables and Arithmetic Operators #04 All Loops + more Math ->

Remember: I'm not a genius too! I'm 16 years old but I know quite a lot, because Java or programming in general is fascinating me so much (and yes I have friends and other hobbies :)). So don't give up! Follow you dreams and in some day, they will get true.
Sort:  

Good stuff!

Will be helpful, my teacher at school was not really good at teaching Java!

I wish you all the best.

Feel free to check out my blog @maxdigi, this way we can support each other!

Cheers
maxidigi

Coin Marketplace

STEEM 0.23
TRX 0.26
JST 0.040
BTC 98185.12
ETH 3486.20
USDT 1.00
SBD 3.27