Java Output Statement (System.out.println) explained - Java Tutorial for Beginners

Veröffentlicht am: 24 Dezember 2019
auf dem Kanal: Career & Tech HQ
195
3

Java Tutorial - Explaining The Java Output Statement (System.out.println)

In this video I am explaining the Java Output Statement, using this portion of code

public class MyFirstJavaProject
{
public static void main(String[] args)
{
System.out.println("Hello World! This is my first Program");
System.out.println("The sum of 2 and 7 is " + 9);
System.out.println("9 + 5 is equal to " + (9+5));
}
}

When this potion of code is compiled and executed, the following three lines
are displayed in the Eclipse console:

Hello World! This is my first Program
The sum of 2 and 7 is 9
9 + 5 is equal to 14

Explanation:

System.out.println("Hello World! This is my first Program");
This is a classic example of a Java output statement. It actually tells our program to evaluate whatever is written in the parentheses and display the result in the console. Typically, anything written inside the double quotation marks, is considered to be a String and evaluates to itself, that is, its value is the string itself (nb: without quotation marks). Thus, the statement causes the system to display the following line on the screen:
Hello World! This is my first Program


System.out.println("The sum of 2 and 7 is " + 9);
In this output statement, the parentheses contain the string "The sum of 2 and 7 is " , +
(the plus sign), and the number 9. Here the symbol + is used to concatenate (join) the
operands. In this case, the system automatically converts the number 9 into a string, joins
that string with the first string, and displays the following line on the screen:
The sum of 2 and 7 is 9

System.out.println("9 + 5 is equal to " + (9+5));
In this output statement, the parentheses contain the string "9 + 5 is equal to ", + (the plus sign), and
the expression (9+5). In the expression (9+5), notice the parentheses around 9+5.
This is to tell the system to add the numbers 9 and 5, resulting in 14. And then the number 14 is then
converted into the string "14" and then concatenated or joined with the string "9 + 5 is equal to ". Thus, the output of this statement is: 9 + 5 is equal to 14


Auf dieser Seite können Sie das Online-Video Java Output Statement (System.out.println) explained - Java Tutorial for Beginners mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Career & Tech HQ 24 Dezember 2019 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 195 Mal angesehen und es wurde von 3 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!