CodeGym /Courses /Java Syntax /print() and println();

print() and println();

Java Syntax
Level 1 , Lesson 7
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
New Java Syntax, level 1, lesson 7
Locked
Nerd break
The super secret CodeGym training center has both standard lessons and entertaining lessons. But we don't have them just for the sake of having them. They will teach you loads about your future field of employment! It's time to relax a bit and watch a video about your future colleagues.

"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."

Comments (115)
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION
ganesh chittalwar Level 1, india, India
26 August 2021
great site very interesting ...all topic will understand easily
Indranil Chakraborty Level 3, United Kingdom
3 August 2021
What is the difference between print() and println()
Rex Level 3, Columbus, United States
12 August 2021
print() simply prints whatever you type and nothing more. think of println() as "print line" it prints your text and then prints a line so that whatever is entered next skips to the next line.
Anonymous #10768568 Level 2, United States of America
11 July 2021
will i just run out of dark matter????
Jakhongir Level 2, Tashkent, Uzbekistan
16 February 2021
So far, so good.
Mark Level 2, Madrid, Spain
30 September 2020
I don't understand why double c adds 0. after it. Could anyone give me a hand so I can understand why?
Tim Level 20, Vernon Hills, United States
1 October 2020
It's just Java's standard. When changed to a string or when printed out using a println(), double type variables will display with at least one value after the decimal point (even if it is a whole integer so the value is a 0). You can change this if you want (ie you can show a specific number of digits after the decimal) but that's something to learn later on. That's why it's showing 53.0 instead of 53
Mark Level 2, Madrid, Spain
1 October 2020
Thank you very much!!!
Anthony Fenner Level 3, Seattle, United States
18 October 2020
Double stores larger numbers in a float type but is more accurate than float... specifically if you were doing physics, you may need every number after a decimal to be 100% accurate. 9.444444443 vs float which would make it 9.4444444443. https://people.eecs.berkeley.edu/~wkahan/JAVAhurt.pdf This flaw is the same flaw found in Superman 3 as well as Office Space. Basically, where does the .00000001 go? Someone could attempt to steal that tiny bit of money, which after each transaction totaling into the millions or billions, would lead to having thousands or even hundreds of thousands of dollars. In the movie office space, the math was bad, and they ended up taking too much out because they didn't use enough digits after the number. With that all said, even double has its flaws, similar to float, to which it is recommended anyone working with money not play with either....
Margaret Level 2, Columbus, United States
18 April 2021
Mark, I hope you got the answer and proceeded well. My simple answer is, when int b = 15 is assigned to a double it automatically has to have a decimal place. Note that double data type has to have a decimal value. Note that in the case of double c = b + 38, ideally it is double c = 15.0 + 38.0. Reason being a double data type has to have a decimal place and when a whole number is given it is automatically converted to point zero. to understand it better read more on Java data types. Thanks
Richard Level 2, Columbia, United States
17 July 2020
I did not expect the double variable to automatically place a .0 next to the number. Makes sense though. Pretty cool!
Innocent O. Level 5, Munich, Germany
4 July 2020
How many levels can i complete within a month? And how long does it take to get to level 41 if i study 4 hours a day?
Agent Smith Level 38
9 August 2020
1 month - 12 months or even more, depending on your starting knowledge and skills. Also, rushing is not the goal here. You should really advance only when you mastered the material.
Gigi Suchan Level 3, Los Angeles, United States
2 July 2020
/* Comment has been deleted */
Alex Vypirailenko Level 41, USA
3 July 2020
Not at the moment, unfortunately, but we're working on it.
remote87 Level 18, Sofia, Bulgaria
9 September 2020
I was wondering that too, it's really not cool with those achievements always popping out
FormulaEagle Level 6, Rockville, United States
27 June 2020
i cant get the lines one....
Demory Green Level 1, Broken Arrow, United States
13 June 2020
Can't go forward without buying premium subscription?
John Squirrels Level 41, San Francisco, Poland
15 June 2020
Hi. You can enjoy the Games section and Level 0 of our course for free. In order to continue with the course after Level 0, you will require one of our paid subscriptions.