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
En esta página del sitio puede ver el video en línea Java Output Statement (System.out.println) explained - Java Tutorial for Beginners de Duración hora minuto segunda en buena calidad , que subió el usuario Career & Tech HQ 24 diciembre 2019, comparta el enlace con amigos y conocidos, en youtube este video ya ha sido visto 195 veces y le gustó 3 a los espectadores. Disfruta viendo!