Screen output

Module 1. Java Syntax
Level 1 , Lesson 6
Available

1. Parameters of the println() method

A method body consists of commands. You could even say that a method is a group of commands that has been given a name, i.e. the method name. Either perspective is accurate.

There are different kinds of commands. The Java language has a command for every occasion. Each command defines some specific action. A semicolon goes at the end of each command.

Examples of commands:

Command Description (what it does)
System.out.println(1);
Displays a number on the screen:
1
System.out.println("Amigo");
Displays text on the screen:
Amigo
System.out.println("Risha & Amigo");
Displays text on the screen:
Risha & Amigo

Actually, this is just one command — System.out.println. The arguments passed to it are contained in the parentheses. Depending on the value of the parameters, a command can perform various actions. This is super convenient.

Important:

In Java, size matters in terms whether the letters in a method are uppercase or lowercase. The System.out.println() command will work, but system.out.println() will not.

If you want to display text, you need to mark it on both sides with double quotes.

A single quote looks like this ', and a double quote looks like this ". A double quote is not two single quotes: please don't get confused by that.

The double quotes symbol is the one next to the Enter key.


2. Differences between println() and print()

There are two variations of the command for screen output: System.out.println() and System.out.print()

If you write the System.out.println() command several times, each time the passed text will be displayed on a new line. If you use System.out.print(), then the text will be displayed on the same line. Example:

Commands What will be displayed
System.out.println("Amigo");
System.out.println("IsThe");
System.out.println("Best");
Amigo
IsThe
Best
System.out.print("Amigo");
System.out.println("IsThe");
System.out.print("Best");
AmigoIsThe
Best
System.out.print("Amigo");
System.out.print("IsThe");
System.out.print("Best");
AmigoIsTheBest

A small note. The println() command does not display the text on a new line. Instead, it displays text on the current line — the next text that is displayed will appear on a new line.

The println() command displays text and then adds a special invisible newline character. As a result, the next text will be displayed at the beginning of a new line.

This is what the fully written program will look like, along with a declaration of an Amigo class and a main method. Keep your eyes on the screen:

public class Amigo
{
   public static void main (String[] args)
   {
      System.out.print("Amigo ");
      System.out.print("The ");
      System.out.print("Best");
   }
}
Program with a declaration of the Amigo class and main method

1
Task
New Java Syntax, level 1, lesson 6
Locked
No comments needed
Uncomment one line so that the program displays the numbers 12 and 2 (first 12, and then 2).
1
Task
New Java Syntax, level 1, lesson 6
Locked
2 + 3 = 5
Comment out a few lines to display "2 plus 3 is equal to 5" on the screen. Note: Don't comment out the lines with variable declarations.
1
Task
New Java Syntax, level 1, lesson 6
Locked
Uh... Happy New Year!
Remove comments from part of the code so that "Happy New Year" appears on the screen.
1
Task
New Java Syntax, level 1, lesson 6
Locked
Comment out the superfluous
Comment out some code so that "sum = 12" appears on the screen.
Comments (106)
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION
solosnyuk Level 3, Brest, Belarus
27 November 2024
Public class Amigo { Public static void main (String[]args) { System.out.println("Amigo is very smart"); } }
sharmila sharmila Level 1, India
21 July 2024
public class Programmer{ public static void main(String[] args){ System.out.println("I think being a programmer is cool"); } }
Anonymous #11453057 Level 2, Durham, India
2 July 2024
Public class Amigo { Public static void main (String[]args) { System.out.println("Amigo is very smart"); } }
chosen Level 3, lagos, Nigeria
19 May 2024
i wish u all best of luck
Devanshu Mishra Level 5, Pune, India
8 May 2024
System.out.print("Superb");
Anonymous #11494994 Level 2, China, Hong Kong
29 April 2024
Public class Programmer { Public static void main (String [] args){ System.out.println("I think being a programmer is cool"); } }
Anonymous #11498122 Level 1, Islamabad, Pakistan
4 April 2024
package com.codegym.task.task01.task0101; /* I think being a programmer is cool */ public class Solution { public static void main(String[] args) { //write your code here System.out.print("I think"); System.out.print(" being a programmer "); System.out.print("is cool"); } }
Anonymous #11488918 Level 1, United States
1 April 2024
public class Hello{ public static void main(String[] args){ System.out.println(" Hello World"); } }
K.... Level 1, Philippines
27 March 2024
System. out. print ("hello") ; Sytem. out. print1n ("world") ; System. out. print ("hi") ;
K.... Level 1, Philippines
27 March 2024
System.out.pr1nt ("kieth");