5 Replies - 337 Views - Last Post: 13 April 2011 - 12:18 PM Rate Topic: -----

#1 WinkyCode  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 9
  • View blog
  • Posts: 155
  • Joined: 23-February 11

A simple question about making rows in Java

Posted 13 April 2011 - 08:02 AM

Dear following members of DIC,
:genius:

I wish to learn how to make an extra row when I compile a bit of Java. I have also search for this question and the result has yielded in more complete programs then I am aiming for, like making address books and such. My aim is to learn how to write three 3 rows of text. Like this:

Quote

This is the first row of text,
and this is the second text
and why not a third one?


OK. I try to write it and here is my code:
public class Test1{
	public static void main(String[] args){
		System.out.print ("This is the first row of text, ");
		System.out.print ("and this is the second text ");
		System.out.print (and why not a third one? ");
	}
}



And the cmd (Command Prompt) gives me the following result:
C:\Documents and Settings\Leopold Birkholm\Mina dokument\SchoolJava>javac Test1.
java
Test1.java:5: ')' expected
                System.out.print (and why not a third one? ");
                                     ^
Test1.java:5: ';' expected
                System.out.print (and why not a third one? ");
                                               ^
Test1.java:5: ';' expected
                System.out.print (and why not a third one? ");
                                                         ^
Test1.java:5: unclosed string literal
                System.out.print (and why not a third one? ");
                                                           ^
4 errors



What do I wrong? :cry2:

Yours Truly
Winky ^^

Is This A Good Question/Topic? 0
  • +

Replies To: A simple question about making rows in Java

#2 mi14chal  Icon User is offline

  • D.I.C Head

Reputation: 81
  • View blog
  • Posts: 202
  • Joined: 11-December 10

Re: A simple question about making rows in Java

Posted 13 April 2011 - 08:15 AM

In line 5 in your file you forgot add quotation mark in function System.out.print, and if you want to have a new line you should use a function System.out.println
Was This Post Helpful? 1
  • +
  • -

#3 WinkyCode  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 9
  • View blog
  • Posts: 155
  • Joined: 23-February 11

Re: A simple question about making rows in Java

Posted 13 April 2011 - 08:43 AM

View Postmi14chal, on 13 April 2011 - 08:15 AM, said:

In line 5 in your file you forgot add quotation mark in function System.out.print, and if you want to have a new line you should use a function System.out.println


Thank you mi14chal for your response. It worked, sort of. I got down to 2 errors. :whistling:

Here is the new code:
public class Test1{
	public static void main(String[] args){
		System.out.print ("This is the first row of text, ");
		System.out.printnl ("and this is the second text ");
		System.out.printnl ("and why not a third one? ");
	}
}



And here is the new error message:
C:\Documents and Settings\Leopold Birkholm\Mina dokument\SchoolJava>javac Test1.
java
Test1.java:4: cannot find symbol
symbol  : method printnl(java.lang.String)
location: class java.io.PrintStream
                System.out.printnl ("and this is the second text ");
                          ^
Test1.java:5: cannot find symbol
symbol  : method printnl(java.lang.String)
location: class java.io.PrintStream
                System.out.printnl ("and why not a third one? ");
                          ^
2 errors



What are I missing? Beside correct English? :sad3:
Was This Post Helpful? 0
  • +
  • -

#4 mi14chal  Icon User is offline

  • D.I.C Head

Reputation: 81
  • View blog
  • Posts: 202
  • Joined: 11-December 10

Re: A simple question about making rows in Java

Posted 13 April 2011 - 08:53 AM

NOT System.out.printnl only: System.out.println. On future you will should carefully read my post.
Was This Post Helpful? 1
  • +
  • -

#5 macosxnerd101  Icon User is offline

  • Self-Trained Economist
  • member icon




Reputation: 10468
  • View blog
  • Posts: 38,799
  • Joined: 27-December 08

Re: A simple question about making rows in Java

Posted 13 April 2011 - 09:01 AM

Moved to Java Help. Please reserve the Java Programmers forum for topical, non-help related discussion.
Was This Post Helpful? 1
  • +
  • -

#6 WinkyCode  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 9
  • View blog
  • Posts: 155
  • Joined: 23-February 11

Re: A simple question about making rows in Java

Posted 13 April 2011 - 12:18 PM

View Postmi14chal, on 13 April 2011 - 08:53 AM, said:

NOT System.out.printnl only: System.out.println. On future you will should carefully read my post.


mi14chal, you are so right. It is ln, not nl. I am sorry that I missed that. It works now as it should.

The code input:
public class Test1{
	public static void main(String[] args){
		System.out.println ("This is the first row of text, ");
		System.out.println ("and this is the second text ");
		System.out.println ("and why not a third one? ");
	}
}



and the output in the Command Prompt is:

C:...\Mina dokument\SchoolJava>java Test1
This is the first row of text,
and this is the second text
and why not a third one?



Thank you for your help :flowers: .

Yours Truly
Winky ^^

View Postmacosxnerd101, on 13 April 2011 - 09:01 AM, said:

Moved to Java Help. Please reserve the Java Programmers forum for topical, non-help related discussion.


macosxnerd101, thank you for putting this question in the right forum :flowers: .

Yours Truly
Winky ^^
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1