ba2 ba2 - 1 month ago 6
Java Question

How can I add a space in between two outputs?

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

Answer

Add a literal space, or a tab:

public void displayCustomerInfo() {
    System.out.println(Name + " " + Income);

    // or a tab
    System.out.println(Name + "\t" + Income);
}
Comments