This is the code I am working with.
public void displayCustomerInfo() {
System.out.println(Name + Income);
}
I use a separate main method with this code to call the method above:
first.displayCustomerInfo();
second.displayCustomerInfo();
third.displayCustomerInfo();
Is there a way to easily add spaces between the outputs? This is what it currently looks like:
Jaden100000.0
Angela70000.0
Bob10000.0
The simplest way to properly space your output in Java is by adding manual spacing. For instance, to output three different integers, "i," "j" and "k," with a space between each integer, use the following code: System. out.
"\t" format specifier is used in println() function to leave tab space in the console.
We add space in string in python by using rjust(), ljust(), center() method. To add space between variables in python we can use print() and list the variables separate them by using a comma or by using the format() function.
In Windows, a new line is denoted using “\r\n”, sometimes called a Carriage Return and Line Feed, or CRLF. Adding a new line in Java is as simple as including “\n” , “\r”, or “\r\n” at the end of our string.
Add a literal space, or a tab:
public void displayCustomerInfo() {
System.out.println(Name + " " + Income);
// or a tab
System.out.println(Name + "\t" + Income);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With