printing multiple lines of output

/n didnt seem to work for me, need assistance

Page 1 of 1

3 Replies - 8840 Views - Last Post: 21 January 2010 - 03:35 PM Rate Topic: -----

#1 kweef19  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 108
  • Joined: 19-January 10

printing multiple lines of output

Post icon  Posted 21 January 2010 - 03:31 PM

public class Tree
{
	public static void main(String[] args)
	{
		System.out.println("   X	/n   XXX  /n xxxxx /n xxxxxxx/n	x   ");
		
	}
}
 
I am very green when it comes to Java. I know some VB, but I'm used to more object oriented language. I really just need someone to show me the correct format for multiple lines of output. I'm sure there is more than one way to accomplish this task, but I am looking for the simplest.

Is This A Good Question/Topic? 0
  • +

Replies To: printing multiple lines of output

#2 erik.price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 485
  • View blog
  • Posts: 2,690
  • Joined: 18-December 08

Re: printing multiple lines of output

Posted 21 January 2010 - 03:33 PM

\n, not /n

Just so you know, \ is used for all escape sequences. Here's a short tutorial on them (and characters in general) http://java.sun.com/...characters.html

This post has been edited by erik.price: 21 January 2010 - 03:38 PM

Was This Post Helpful? 0
  • +
  • -

#3 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10803
  • View blog
  • Posts: 40,262
  • Joined: 27-December 08

Re: printing multiple lines of output

Posted 21 January 2010 - 03:33 PM

You're new line escape sequence is wrong. You need to use \n instead of /n. You can also use multiple println() statements, as println() adds a \n to the end of each line automatically.

Edit: Erik.price beat me.

This post has been edited by macosxnerd101: 21 January 2010 - 03:34 PM

Was This Post Helpful? 1
  • +
  • -

#4 Dogstopper  Icon User is offline

  • The Ninjaducky
  • member icon



Reputation: 2876
  • View blog
  • Posts: 11,051
  • Joined: 15-July 08

Re: printing multiple lines of output

Posted 21 January 2010 - 03:35 PM

System.out.println() by default adds a newline character at the end of whatever it's outputting. The newline character ("\n") can be added anywhere to start a new line, even in text that isn't new by default;

System.out.print("Sometext\n"); // This imitates println()...



As you can see, there are different ways to do it, and those ways are based on preference.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1