• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to go down a row inside the brackets of the command System.out.println();

 
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello guys, i would like to know how to keep writing  something to print inside the command System.out.println(); ,
but everytime that im trying to go down a raw it writes me an compilation error: " ); expected " or" illegal start of expression"..
how can i go down a raw without errors?

e.g.: System.out.println("Enter a number between 1 to 10
and remember it");

thank you guys:)
 
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't try to do that with System.out.println. Try with System.out.printf. Try the %n tags and the \f escape. More details in the Formatter documentation (lots of scrolling required), the Java™ Tutorials (link 1) (link 2) and the Java® Language Specification (=JLS).I have never seen anybody use \f other than simply finding out how it works, and I cannot remember whether it behaves the same on Linux, other Unix‑like system, and Windows®. You might do well to avoid \f. Don't try using what appears to be the corresponding Unicode escape \u000c.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you can use "\n" for line break, like this.
 
Sheriff
Posts: 7125
184
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can, but it will make that statement platform-dependent.

And welcome to the Ranch!
 
Campbell Ritchie
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome again

Only us \n and \r if someboyd has told you they want a particular combination of characters. The %n tag gives you the correct line end for your current operating system.
 
Campbell Ritchie
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I merged your stuff with the following thread. I hope that is okay by you.
 
rian bron
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello guys, when im writing a code and dont want it to last outside the line, im going down  a raw inside the command "System.out.println();" and then when im trying to compile it  , it writes: "";"expected", how can i keep writing without getting this error?

For example:

public class Tester
{
public static void main(String[]args)
{
System.out.println("Hello everyone my name is
ryan and im trying to write a code");
}
}

Thank you all for your solutions
 
Campbell Ritchie
Marshal
Posts: 79239
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please don't ask the same question twice; fortunately I can merge the two topics.

You cannot break lines in the middle of a String literal. You have to use the String concatenation operator.Sorry, we seem to have misunderstood the question earlier.
 
Marshal
Posts: 4510
572
VSCode Eclipse IDE TypeScript Redhat MicroProfile Quarkus Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I noticed in both of your examples, that the string that you are wanting to print is broken on to two lines.  Is that actually how you have the code in your editor/IDE?
 
rian bron
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Please don't ask the same question twice; fortunately I can merge the two topics.

You cannot break lines in the middle of a String literal. You have to use the String concatenation operator.Sorry, we seem to have misunderstood the question earlier.



Yeah sorry i forgot i asked this question a week ago ;/

sorry
 
rian bron
Ranch Hand
Posts: 117
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Campbell Ritchie wrote:Please don't ask the same question twice; fortunately I can merge the two topics.

You cannot break lines in the middle of a String literal. You have to use the String concatenation operator.Sorry, we seem to have misunderstood the question earlier.



YEAH! that's the solution i wanted to find
Thank you !
reply
    Bookmark Topic Watch Topic
  • New Topic