Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Synchronizing Block code

 
wong sheena
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Hi guys, this is the exercise 9 -2 on pg 710 of k & b. I did a comparison at line 1 and change the StringBuffer object. Is there any other way to do the comparison and increment the letter?
 
Giovanni Murguia
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!

You could try something like:


Giovanni
 
Brad Clarke
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This particular exercise baffled me, but for a different reason this time

The verbiage of the question states "You can check Chapter 6 for StringBuffer methods that will help with this." so I took it literally to mean that the only methods that applied to the exercise were the ones discussed in the StringBuffer/StringBuilder section in chapter 6.

The charAt() and setCharAt() methods were never discussed in the context of StringBuffers/StringBuilders in Chapter 6.
[ June 20, 2007: Message edited by: Brad Clarke ]
 
Louie Cheung
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Giovanni Murguia:
Hello!

You could try something like:


Giovanni


i'm getting compiler error for the above code as follows:

cannot find symbol
symbol : method setCharAt(int, int)
location: class java.lang.StringBuffer
sb.setCharAt(0, letter+1);

i tested if i change it to the following it compiles fine:
sb.setCharAt(0, letter);

so what's wrong with the +1 there?
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic