• Post Reply Bookmark Topic Watch Topic
  • New Topic

string literal trouble  RSS feed

 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is the code



and here is the error or exceptions i received

C:\java\Lesson1>javac PondRadius.java
PondRadius.java:23: error: ')' expected
System.out.println("To hold" + fishCount + fish averaging " + fishLength +" inch
es long you need a pond with an area of \n" +
^
PondRadius.java:23: error: not a statement
System.out.println("To hold" + fishCount + fish averaging " + fishLength +" inch
es long you need a pond with an area of \n" +
^
PondRadius.java:23: error: ';' expected
System.out.println("To hold" + fishCount + fish averaging " + fishLength +" inch
es long you need a pond with an area of \n" +
^
PondRadius.java:23: error: not a statement
System.out.println("To hold" + fishCount + fish averaging " + fishLength +" inch
es long you need a pond with an area of \n" +
^
PondRadius.java:23: error: ';' expected
System.out.println("To hold" + fishCount + fish averaging " + fishLength +" inch
es long you need a pond with an area of \n" +

^
PondRadius.java:23: error: ';' expected
System.out.println("To hold" + fishCount + fish averaging " + fishLength +" inch
es long you need a pond with an area of \n" +

^
PondRadius.java:23: error: ';' expected
System.out.println("To hold" + fishCount + fish averaging " + fishLength +" inch
es long you need a pond with an area of \n" +

^
PondRadius.java:23: error: ';' expected
System.out.println("To hold" + fishCount + fish averaging " + fishLength +" inch
es long you need a pond with an area of \n" +

^
PondRadius.java:23: error: ';' expected
System.out.println("To hold" + fishCount + fish averaging " + fishLength +" inch
es long you need a pond with an area of \n" +

^
PondRadius.java:23: error: illegal character: \92
System.out.println("To hold" + fishCount + fish averaging " + fishLength +" inch
es long you need a pond with an area of \n" +

^
PondRadius.java:23: error: not a statement
System.out.println("To hold" + fishCount + fish averaging " + fishLength +" inch
es long you need a pond with an area of \n" +

^
PondRadius.java:23: error: unclosed string literal
System.out.println("To hold" + fishCount + fish averaging " + fishLength +" inch
es long you need a pond with an area of \n" +

^
PondRadius.java:23: error: not a statement
System.out.println("To hold" + fishCount + fish averaging " + fishLength +" inch
es long you need a pond with an area of \n" +

^
PondRadius.java:24: error: not a statement
pondArea + " square feet.");
^
PondRadius.java:24: error: ';' expected
pondArea + " square feet.");
^
15 errors

 
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to put the whole string on one line; you cannot start a new line in the middle of a string literal.

If you really don't want to put everything on one line, then use + to concatenate literals:
 
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Start by putting string literals onto single lines, not spread them over multiple lines.

The same goes for comments. For example, I assume line 23 should be part of the comment after line 21, but currently it's not.
 
Donald Gooden
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks guys that cleared up most of the errors

i understand the + symbol is for concatenation connecting characters in a string literal

i dont understand the significance of the double quotes and what they represent ?

 
Ranch Hand
Posts: 355
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Donald,
I am sure that you can find the solutions to the errors in your program yourself by looking at the lines where these occurred. The lines mentioned are 23 and 24. So inspect those well. For instance, in this line

there is a " after the word averaging that has no opening "

Oh, i think you said your errors are now cleared
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Double quotes terminate string literals on both sides; you can't use them across line breaks (meaning, a string literal can't start on one line, and then continue on the next).
 
Paul Ngom
Ranch Hand
Posts: 355
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And an instruction may appear on one line in your program but when it is posted, it may span many lines. So it is difficult to inspect it. To avoid that, break line across many in your program and follow what Ulf has said on strings.
 
Donald Gooden
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys for the help and guidance!!!

i apologize for the all caps they were in exuberance not yelling
 
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Ngom wrote:For instance, in this line...

Paul,

Please DontWriteLongLines (I notice you actually changed the line you quoted to make it even longer). It makes threads very difficult to read. I've broken it up for you this time (and actually added a missing quote).

Thanks.

Winston
 
Ranch Hand
Posts: 43
2
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[Not related to the question asked]


How about writing this way? I think its more clean and readable.

 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Amar Saikia wrote:How about writing this way? I think its more clean and readable.

I totally agree; and your naming suggests some more things:

int numberOfFish = 20;
int avgFishLength = 10;
int fishLengthPerSqFt = 2;

belong in a Fish or FishStats class; and then you could name them:
int count = 20;
int avgLength = 10;
int lengthPerSqFt = 2;


Similary:
double pondRadius = 0.0;
belongs in a Pond class, where it becomes:
double radius = 0.0;

and:
int inchesPerFoot = 12;
probably belongs in a Measurements class.

Naming is simple when you have the right context.

Winston
 
Donald Gooden
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks guys for the naming advice but im working out of ivor hortons beginning java , java 7 edition
and i am a complete noob so im just copying his examples typing them in compiling and running them and coming here when i need help thanks again
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!