Skip to content
← Back to Community
New Line
Profile icon
talynnhardy

How to start a new line? Is my coding correct so far? Please let me know.

Answered by RYANTADIPARTHI [earned 5 cycles]
View Answer
Voters
Profile icon
VeronikaVitrik
Profile icon
talynnhardy
Comments
hotnewtop
Profile icon
RYANTADIPARTHI

Solution

to put a new line in java, use \n.

class Main { public static void main(String[] args) { System.out.print("Enter the monthly subscription fee: \n"); # newline System.out.print("9.99"); System.out.print("Enter the number of paying customers: \n"); # newline System.out.print("26000000"); System.out.print("This company makes $259740000 per month"); System.out.print("This company makes $3116880000 per year"); } }

like that. You can add more.
It should work

Profile icon
IntellectualGuy

Easy just put \n

class Main { public static void main(String[] args) { System.out.print("Enter the monthly subscription fee:\n"); System.out.print("9.99"); System.out.print("Enter the number of paying customers:\n"); System.out.print("26000000"); System.out.print("This company makes $259740000 per month"); System.out.print("This company makes $3116880000 per year"); } }

or you could write System.out.println instead of System.out.print, both of those should work


Btw I suggest using proper indentation in java, it can make your code way easier to read

Profile icon
EpicGamer007

to print a new line, put \n in the string

Profile icon
ObiVibKenobi

Hi there! I don’t know much java, but I do know that to print a new line, you could replace print with printf and put in %n where new lines should be. So, you could replace your code with this:

class Main { public static void main(String[] args) { System.out.printf("Enter the monthly subscription fee:"); System.out.printf("%n9.99"); System.out.printf("%nEnter the number of paying customers:"); System.out.printf("%n26000000"); System.out.printf("%nThis company makes $259740000 per month"); System.out.printf("%nThis company makes $3116880000 per year"); } }