At this point you need to have read chapters 1, 4 and 7 in that order. And had the two previous homework assignments completed and returned to you. Now read chapter 5. Assignment 3: Write a program that will read in a year and report if it is a leap year. The tricky thing here is that a leap year occurs:
on every year that is evenly divisible by 4
except every year that is evenly divisible by 100
except every year that is evenly divisible by 400.
Assignment 4: Write a program that will read in a number from 0 to 99 and spell out that number. The program must also report any values that are out of range. In other words, I want to type
java Say 22
Extra credit if you can do it with less than 30 strings. More extra credit if you can handle numbers as large as nine hundred ninety-nine billion, nine hundred ninety-nine million, nine hundred ninety-nine thousand, nine hundred ninety-nine.
[This message has been edited by Paul Wheaton (edited February 04, 1999).]
Being the student that I am, I have a question about arrays in chapter 5. I have dealt with arrays in C and the book even says that they are alike in syntax alone (p.109 Just Java 1.2). O.k., I can deal with that. Unfortunately the book is gets more confusing as you read along. For example, on p.112 where there is greyed text it says: "You can never specify the size of an array in a C-style declaration like this: <PRE> int sprout ; //NO! </PRE> The array's size is set when you assign something to it, either in an initializer or a regular assignment statement. <PRE> carrot  = new int; </PRE> Once an array object has been created with a given size, it cannot change for that array, although you can replace it by assigning a differently-sized array object to it." Whoaa. Give me a second to stop my eyes from spinning round and round. I get the first part, int sprout , is a no-no. On the second part, what happened here? Did carrot get assigned as an int array with 256 elements? This is what I think is happening. Could someone explain it to me if I am wrong. I guess the confusion comes from when they say "The array's size is set when you assign something to it, either in an initializer or a regular assignment statement". To me, nothing has been assigned to "it", and yes the array appears to be initialized, but NOTHING is assigned to it when INITIALIZED either. Am I right? Thanks for putting up with the newbie questions but its better to learn it here, than get burnt by it out there!
I think you found a typo in the book. Somewhere in the book the author mentions that if you tell him he'll give you money. Might wanna cruise over to his web site! I think the carrot line should read: <pre> int carrot = new int[ 256 ]; </pre> although I would have used <pre> int carrot = new int[ 256 ]; </pre> Does this fix everything? Basically, all arrays are objects. so "int" is like a class called "ArrayOfInt". So you could start with "int carrot = null;" and later do "carrot = new int[ 256 ];". Still lost?
By the way, I did send Mr. Peter Van Der Linden an e-mail. I humbly asked him if he thought it was a typo and he immediately replied. He said it was a typo and sent me a small list of other typos that are known so far. Most are trivial. He really seemed like an approachable, cool guy from his e-mail. Truly an excellent personality that all developers should be modeled from.
If you check out www.split.com/jj you will find my exchnages with him when I tried to do some of the homework from his book. You are just seeing the beginning of his coolness. Check out his web page and find some really cool stuff. Maybe you could post that list here somewhere. I'm tempted to create a forum called "Peter van der Linden" - but ....