Java Output
As you recall from the previous chapter, the println() function in Java allows you to produce text or values:
System.out.println("Hello World!");
You are able to add an unlimited number of println() methods. It should be noted that every procedure will create a new line:
System.out.println("Hello World!");
System.out.println("I am learning Java.");
System.out.println("It is awesome!");
When working with text, it needs to be encircled by double quote marks ” “.
An error happens if the double quotes are forgotten:
System.out.println("This sentence will work!");
System.out.println(This sentence will produce an error);
A print() method that is comparable to println() is also available.
The sole distinction is that the output ends without a new line being inserted:
System.out.print("Hello World! ");
System.out.print("I will print on the same line.");
Take note that in the sample above, we have included an extra space (after “Hello World!”) for easier reading.
We will only use println() in this lesson because it makes code output easier to read.
CodingAsk.com is designed for learning and practice. Examples may be made simpler to aid understanding. Tutorials, references, and examples are regularly checked for mistakes, but we cannot guarantee complete accuracy. By using CodingAsk.com, you agree to our terms of use, cookie, and privacy policy.
Copyright 2010-2024 by Refsnes Data. All Rights Reserved.