Right now the lines inside the while loop "You will be charged a fee of 10 dollars " and " Would you like to close your account?" appear on separate lines like...
"you will be charged a fee of 10 dollars."
"Would you like instructions?"
How do I change the formatting of my code so both statements are printed on a single line. The program should still work the same. The answer should appear as
"You will be charged a fee of 10 dollars. Would you like to close your account?"
import acm.program.*;
public class BankAccount extends ConsoleProgram {
public void run() {
int bankRoll = 50;
while(bankRoll > 0) {
println("Currently your balance is " + bankRoll + " . ");
println("You will be charged a fee of 10 dollars.");
String closeAct = readLine("Would you like to close your account?");
if(closeAct.equals("yes")) {
break;
}
bankroll -= 10;
} /* end of while loop */
println("your account is now closed.");
}
}
You have to use print instead of println.
println is like print, but at the end of the String, it adds a "\n" which is the newline character.
If you want to make more than one line, you can also use print and add a "\n" where you want to have a break.
For instance:
print("This is an example with one line")
print("This is still in the same line as the text ahead.")
if you want to make 2 lines, but have 1 one String, you can also
print("This is an example with 2 lines" + "\n" + "but only 1 String")
println would make the "\n" at the end of the line so like before
println("This is an example with two lines") // Here is an automatically added "\n"
print ("This text is in the next line")
Use print rather than println where appropriate to suppress the newline character.
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