File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Synchronizing Block code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Synchronizing Block code" Watch "Synchronizing Block code" New topic

Synchronizing Block code

wong sheena

Joined: Apr 07, 2007
Posts: 23

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

Joined: May 04, 2007
Posts: 6

You could try something like:

Brad Clarke

Joined: Mar 27, 2006
Posts: 20
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

Joined: Dec 25, 2006
Posts: 17
Originally posted by Giovanni Murguia:

You could try something like:


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?
I agree. Here's the link:
subject: Synchronizing Block code
It's not a secret anymore!