//print and create new line after
System.out.println("text");
System.out.println(String);
//You can use any variable type, not just strings, although
//they are the most common
//Print without creating a new line
System.out.print("text");
System.out.print(String);
System.out.print(<string>); //prints in the same line as the previous print
System.out.println(<string>); //prints in a new line
// Example
System.out.print("This ");
System.out.print("will ");
System.out.print("be ");
System.out.print("all ");
System.out.print("in ");
System.out.print("one ");
System.out.print("line.");
System.out.println("Hello World!");
System.out.println("second line");
/* The println() function adds a new line after printing
the value/data inside it. Here, the suffix ln works as the
newline character,
. If you consider the following example:
*/
public class Main{
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
/* You might not figure out exactly what is happening under
the hood as you are printing only one line,
and you get the following output:
*/
// Hello World!
/* But if you try to print several different expressions
using the println() then you'll see the difference clearly!
*/
public class Main{
public static void main(String[] args) {
System.out.println("Hello World!");
System.out.println("Welcome to freeCodeCamp");
}
}
/* Here, you can see that after executing the first print
statement, it is adding one new line character (
).
So you are getting the second print statement,
Welcome to freeCodeCamp, in the next line.
The whole output will be like below:
*/
// Hello World!
// Welcome to freeCodeCamp
//print and create new line after
System.out.println("text");
System.out.println(String);
//You can use any variable type, not just strings, although
//they are the most common
//Print without creating a new line
System.out.print("text");
System.out.print(String);
System.out.print(<string>); //prints in the same line as the previous print
System.out.println(<string>); //prints in a new line
// Example
System.out.print("This ");
System.out.print("will ");
System.out.print("be ");
System.out.print("all ");
System.out.print("in ");
System.out.print("one ");
System.out.print("line.");
System.out.println("Hello World!");
System.out.println("second line");
/* The println() function adds a new line after printing
the value/data inside it. Here, the suffix ln works as the
newline character,
. If you consider the following example:
*/
public class Main{
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
/* You might not figure out exactly what is happening under
the hood as you are printing only one line,
and you get the following output:
*/
// Hello World!
/* But if you try to print several different expressions
using the println() then you'll see the difference clearly!
*/
public class Main{
public static void main(String[] args) {
System.out.println("Hello World!");
System.out.println("Welcome to freeCodeCamp");
}
}
/* Here, you can see that after executing the first print
statement, it is adding one new line character (
).
So you are getting the second print statement,
Welcome to freeCodeCamp, in the next line.
The whole output will be like below:
*/
// Hello World!
// Welcome to freeCodeCamp