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.
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).
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
posted
0
Take a look around-Processor speed.......wen i execute i keep getting the first element of array is combined with println() function..... hmmmm
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
posted
0
wen i execute i keep getting linkin park is the best
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
posted
0
Thanks you..... This solved it.......
Aman Kulkarni
Greenhorn
Joined: Jan 21, 2012
Posts: 15
posted
0
public class PhaseOMatic
{
public static void main(String args[])
{
String[] wordListOne={"24/7","multi-tier","30,000
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...