File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes phraseomatic code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "phraseomatic code" Watch "phraseomatic code" New topic
Author

phraseomatic code

John Frank
Greenhorn

Joined: Jun 28, 2006
Posts: 4


i have no idea why it doesnt work. at least i cant find an error. i have tried google, found the same code, but it has some problems too.

so i ask myself if the code is the problem

[edited overlong lines - Jim]
[ June 28, 2006: Message edited by: Jim Yingst ]
Christian Nash
Ranch Hand

Joined: Jan 17, 2006
Posts: 107
Hi John,
Hope this solves the problem.


Were u getting an Array outofbounds Exception? Well that was because u were adding a random value to the String array length and the jvm did not find a value at that location.



[ June 28, 2006: Message edited by: Christian Nash ]

[ edited overlong line - Jim ]
[ June 28, 2006: Message edited by: Jim Yingst ]

- Christian
John Frank
Greenhorn

Joined: Jun 28, 2006
Posts: 4
weird....it is exactly this way in the book "head first java".

for the code i posted:
phraseomatic.java:6: cannot find symbol
symbol : class string
location: class phraseomatic
string[] wordListtwo = .....

same for wordlistthree.

i have 3 errors with your change. i dont know exactly where they are because i put the code direct to the editor.

i ll keep heading forward maybe one day i ll find the problem *g*

thank you
[ June 28, 2006: Message edited by: John Frank ]
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24187
    
  34

Java is case sensitive, and all language compilers are picky about the little details.

The error message is saying there's no such class as "string", and that's correct -- it's "String", with a capital S. I see two such errors in your first program.


[Jess in Action][AskingGoodQuestions]
Christian Nash
Ranch Hand

Joined: Jan 17, 2006
Posts: 107
Hi again,

Can't see how the (int)(Math.random() + oneLength) can work. Math.random() gives you a random double value.Then adding oneLength which is 12 and then typecasting it into an int will give you back 12 or more. Hence you should be getting an Array Indexoutofbounds Exception since there is no element for wordListOne[12].
[ June 28, 2006: Message edited by: Christian Nash ]
dee dee three three
Greenhorn

Joined: Jun 28, 2006
Posts: 1
Hi,

Couple of things ( one already mentioned ) - Java is heavily typed, so make sure strings are Strings.

Secondly, try this ...

int rand1 = (int) (Math.random() * oneLength);
int rand2 = (int) (Math.random() * twoLength);
int rand3 = (int) (Math.random() * threeLength);
( * rather then + )

HTH

D
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: phraseomatic code