# 3 questions

• 05-09-2011, 02:08 PM
3 questions
Sorry I put so many questions in my previous post "Thinking in Java book questions" , I realized it was too much to ask the forum to answer all of them. So I Googled them, and solved most of my questions myself, but I am still lost on 3. Please if anyone can help it would be really appreciated. Thanks.

question 1

page 137 of Thinking in Java

why would a method have both "print(result + ", ");" and "return result;" in the same method right next to each other, don't I just need "return result"?

question 2 (page 138)

You can do math on characters?

Code:

`for(char c = 0; c < 128; c++)`
question 3 (page 152)

I don't know what the 'a' is for in the following code.

Code:

`int c = rand.nextInt(26) + 'a'`
(I don't understand the book's explanation.)
• 05-09-2011, 02:15 PM
Toll
It's hard to answer without having read the book myself, but I'll take a shot at it.

A) One prints to the console, the other returns the value to use in the method that called it.

B) Yes. char is a 16-bit value that is used to describe characters. For instance, the character "a" has a value of 97.

C) My guess is that that code randomly selects a character. As described above, all characters have a numerical representation, and there are 26 characters in the English language. What the code says is "Pick a random number between 0 and 26, and pick the character that's that many steps from the character "a".
• 05-09-2011, 02:17 PM
Toll
Oh, and if you want to see which number corresponds to which character, have a look at Ascii Table - ASCII character codes and html, octal, hex and decimal chart conversion which gives you a number in decimal, hexadecimal and octal.
• 05-09-2011, 02:24 PM
j2me64
i have only the html-version of this book. can you please tell which edition you mean and in which chapter i can find the pages you are referring?
• 05-09-2011, 02:42 PM
Toll that was AWESOME. Thank you so much!! I wish I could just read programming books without questions, but every author puts in code that he doesn't first explain. Thank you!
• 05-09-2011, 02:43 PM
That's ok j2me64 Toll answered it. Thank you for responding though. Derek
• 05-09-2011, 02:49 PM
Toll
Glad I could help! Remember to mark it as solved; you can do that under "Thread tools" at the top.
• 05-09-2011, 02:54 PM
Thanks. I tried to mark it as solved, but I got the following error.

Code:

```[B]Content Encoding Error[/B]           The page you are trying to view cannot be shown because it uses an invalid or unsupported form of compression.   Please contact the website owners to inform them of this problem.```
• 05-09-2011, 02:56 PM
Toll
Yeah, it does that. It's marked as solved despite that error!
• 05-09-2011, 02:56 PM