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 syntax problem in Head First Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "PhraseOMatic syntax problem in Head First Java" Watch "PhraseOMatic syntax problem in Head First Java" New topic
Author

PhraseOMatic syntax problem in Head First Java

j rich
Greenhorn

Joined: Jul 12, 2010
Posts: 9
I keep getting loads of errors when trying to compile this, does anyone have an idea what's wrong? I copied it word for word, dot for dot from the book, and I believe it's supposed to compile.


Any help?
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4343
    
    8

In general it might help if you list what the error messages actually are.

In this case, though: you've missed the '{' after 'public class PhraseOMatic'.
j rich
Greenhorn

Joined: Jul 12, 2010
Posts: 9
It's still showing errors after I've added the curly braces.
Matthew Brown
Bartender

Joined: Apr 06, 2010
Posts: 4343
    
    8

What errors?

Edit - actually, quick guess: probably something about String literals not being closed? Don't split your strings over two lines - e.g. "multi-Tier" (if that's exactly how you've formatted it in your program).

You really do need to give the error messages when asking this sort of question, though (see TellTheDetails).
j rich
Greenhorn

Joined: Jul 12, 2010
Posts: 9
Ah, that fixed it, thanks
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Please understand that simply saying "It doesn't work" is useless. So useless, in fact, we have a FAQ for it: ItDoesntWorkIsUseless. So after someone says that it'd help to include *what* errors, to immediately not include the errors *again* isn't the most efficient way to get help. Make it easy for the volunteers who spend their time here to help!

Thanks!
Arun C. Giridharan
Ranch Hand

Joined: Jul 11, 2010
Posts: 96
Take a look around-Processor speed.......wen i execute i keep getting the first element of array is combined with println() function..... hmmmm
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38007
    
  22
Arun Giridharan wrote:Take a look around-Processor speed.......wen i execute i keep getting the first element of array is combined with println() function..... hmmmm
What does that mean? Don't understand.
Arun C. Giridharan
Ranch Hand

Joined: Jul 11, 2010
Posts: 96


wen i execute i keep getting linkin park is the best
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Clearly a design flaw, as of the three performers listed, obviously Clapton is the best.
Hunter McMillen
Ranch Hand

Joined: Mar 13, 2009
Posts: 492

Arun Giridharan wrote:

wen i execute i keep getting linkin park is the best


Well first off this doesn't execute, it causes a compile time error.
The reason you are always getting linkin park is the best is because you're doing this:



This will always evaluate to 0, because Math.random() returns a double less than 1, and when you cast to an integer the right hand side is truncated. So you always end up with 0 * i, which is 0.

I think you meant to do this:



Hunter

"If the facts don't fit the theory, get new facts" --Albert Einstein
Arun C. Giridharan
Ranch Hand

Joined: Jul 11, 2010
Posts: 96
Thanks you..... This solved it.......
Aman Kulkarni
Greenhorn

Joined: Jan 21, 2012
Posts: 15
public class PhaseOMatic
{
public static void main(String args[])
{
String[] wordListOne={"24/7","multi-tier","30,000

foot","B-to-B","win-win","frontend","web-based","pervasive","smart","six-sigma","critical-path","dynamic"};
String[]

wordListTwo={"empowered","sticky","value-added","oriented","centric","distributed","clustered","branded","outside-the-box","

positioned","networked","focused","leveraged","aligned","targeted","shared","cooperative","accelerated"};
String[] wordListThree={"process","tipping-point","solution","archtecture","core

computing","strategy","mindshare","portal","space","vision","paradigm","mission"};
int oneLength=wordListOne.length;
int twoLength=wordListTwo.length;
int threeLength=wordListThree.length;
int rand1=(int)(Math.random()*oneLength);
int rand2=(int)(Math.random()*twoLength);
int rand3=(int)(Math.random()*threeLength);
String phrase=wordListOne[rand1]+" "+wordListTwo[rand2]+" "+wordListThree[rand3];
System.out.println("What we need is a "+phrase);

}
}



This program is 100% error-free and will give correct output...
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Aman Kulkarni wrote:public class PhaseOMatic


First, why are you resurrecting a year-and-a-half-old thread?

Second, don't do others' work for them. This site it NotACodeMill (⇐link).
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38007
    
  22
Welcome to the Ranch

Please make sure to indent your code.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: PhraseOMatic syntax problem in Head First Java
 
Similar Threads
phraseomatic code
Once Over
unclosed string literal error
PhraseOMatic Errors From Head First Java (Help! Please Help! Sobs...)
The correct version of the Phrase-O-Matic (ref:Head First Java)