Java 8 | Print and Println Method + \t

Student Kim
Buzz Code
Published in
3 min readDec 22, 2020

Print/Println — The methods that display the text on the console.

Hi y’all! It’s been a while to post something that’s not a practice session! Today I’m going to explain the different way to print things on the console.

[Println()]

This is the basic printing method we’ve been using, and as we all know, it moves the cursor to the next line after printing the result.

On the example above, it printed “Hi.” and then moved it’s cursor to the next line and printed “It’s Student Kim.”

[Print()]

On the other hand, print method retain cursor at the end of the same line of the former text.

Like this, you can see them printed on the same line. If I use this method to print 0 to 10 with the for loop, it will be printed like below.

When you want some gap between the numbers you can just put some space that are enclosed in the double quotes, or you can also use the “\t”. \ is the backslash, so don’t get confused with the normal slash / . The backslash is usually located above the Enter key.

Ta-da! Now there’s a gap between the numbers! When you use \t, it should be enclosed in the double quotes. Now let’s move to solve a practice question of it!

Question) Print the multiplication table like below.

We’ve already done the multiplication tables, but this time we have to make the tables printed next to each other. If you haven’t been practiced generating multiplication table, checkout my last post!

The answer of this question is right on below.

I put the nested loop, and the variable i in the first loop goes from 1 to 9, and the j in the second loop goes from 2 to 9. So when the variable i is 1, j will be started from 2 and ended with 9. So on the first line, j*i will be 2*1, 3*1, 4*1, 5*1, 6*1, 7*1, 8*1, 9*1 . On the next line i will get bigger. you see?

I hope you could solve this question by yourself, Cause I’ll give you some of the advanced practice questions on our next session! Well done today guys. See ya!

--

--