print() and println();

Available

"Hi, it's me again. I'll give you three lessons today. And this is the second one! Make yourself comfortable and listen up. I'm going to tell you about displaying text on the screen. It's actually very simple:"

Java code What will be displayed on the screen
System.out.println("Diego");
System.out.println(3);
System.out.println("Rain" + "In" + "Spain");
Diego
3
RainInSpain
System.out.println(1 + 3);
System.out.println("1" + "3");
System.out.println(1 + "3");
System.out.println("1" + 3);
System.out.println("1" + (1 + 3));
4
13
13
13
14
System.out.println("Amigo is the best!");
System.out.println("Amigo" + "is the best!");
System.out.println("Amigo" + " " + "is the best!");
Amigo is the best!
Amigois the best!
Amigo is the best!
System.out.println(3 * 3 + 4 * 4);
System.out.println(1 * 2 + 3 * 4);
25
14
System.out.print("Diego");
System.out.print("Diego");
System.out.print("Diego");
DiegoDiegoDiego
System.out.print("Diego ");
System.out.println("is the best!");
System.out.print("Amigo ");
System.out.println("is the best!");
Diego is the best!
Amigo is the best!
1
Task
Java Syntax,  level 1,  lesson 7
unavailable
Code entry
Sometimes you don't need to think, you just need to hammer it out! As paradoxical as it may seem, sometimes your fingers will "remember" better than your conscious mind. That's why while training at the secret CodeGym center you will sometimes encounter tasks that require you to enter code. By entering code, you get used to the syntax and earn a little dark matter. What's more, you combat laziness!

"Could you tell me about print() and println() one more time?"

"The print(), function is used to display text on the screen, character by character. When the screen no longer has room on a line, the text begins to be displayed on the next line. You can use the println() function to stop displaying text on the current line even before it is full. Subsequent text will appear on the next line."

"OK. And what was that trick with adding numbers and strings?"

"If you add two numbers, the result is also a number: 2+2 equals 4. If you add a number and a string, the number is converted to a string. Then the two strings are simply joined together."

"Oh! That's what I thought from looking at the examples, but who knows. Thank you for this interesting lesson, Ellie."

"You're welcome. And finally, here are a few tasks from Diego. He wanted me to check your progress."

1
Task
Java Syntax,  level 1,  lesson 7
unavailable
Finding bugs
If you show me someone who has never once made a programming error, we can say with certainty: you must not be talking about a human. Bug-free programming just doesn't happen. But this isn't so scary. The most important thing is to immediately accept that bugs are inevitable. We search for (or "catch", as professionals sometimes say) and correct bugs.
1
Task
Java Syntax,  level 1,  lesson 7
unavailable
We don't need any extra lines
Inexperienced and, at times, experienced programmers create superfluous code. Just in case. For example, they may declare a couple dozen variables and then not know what to do with them. In this task, someone did something weird, and we get to correct it. Look for unused variables and convert them to comments in order to hide from the compiler.
Comments(80)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Sohail ansariLevel 1 , Saharsa
day before yesterday, 06:36
I love code gym wow amazing way to learn java
Zeshan AhmedLevel 1 , Bahawalnagar
4 November, 18:18
i love its
Mahmudur RahmanLevel 4 , Uppsala
15 September, 11:51
Good way to learn !
MordecaiLevel 1 , Accra
11 September, 22:56
Better
MaGaby2280Level 14 , Guatemala City
4 September, 18:41
String a = "need more concentration"; String b = "need more patience";
Giridhar RajLevel 4 , Hyderabad
31 August, 12:53
good
Stephen BurdenLevel 2 , San Jose
17 August, 19:31
Good courses so far. I had no problem buying a subscription because I can tell this course is well written
Tiffany TownsendLevel 2 , Fort Wayne
19 October, 16:57
Same here. I was skeptical at first, but quickly changed my mind.
Abhijeet DasLevel 3 , Delhi
11 August, 15:03
nice lessons.....
Arslan AshrafLevel 3 , Lahore
27 July, 18:57
Quite Healthy one task!
Gabriella LaPlaceLevel 8 , Basseterre
29 June, 21:21
This question fooled me.