jeudi 27 avril 2017

getting .\Math.java:4: error: -> expected int y=(); in Head First PhraseOMatic Program

I am new to java and am working out of a Head First book. I have installed the latest version of jdk and setup the path to the bin. Everything has been working fine up until this PhraseOMatic mess.

I keep getting numerous errors when trying to compile this program file.

Here is the code

public class PhraseOMatic1
{
public static void main(String args[])
{
String[] wordListOne={"24/7","multi-tier","30,000foot","B-to-B","winwin","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","corecomputing","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);

}
}

Here is what is returned after trying to compile it.

C:\Users\Admin>javac PhraseOMatic1.java
.\Math.java:4: error: -> expected int y=();
    ^
.\Math.java:4: error: ';' expectedint y=();
     ^
.\Math.java:5: error: illegal start of expressionSystem.out.print(x+3==);
  ^
.\Math.java:5: error: ';' expected System.out.print(x+3==);
      ^
.\Math.java:5: error: illegal start of expressionSystem.out.print(x+3==);
                  ^
PhraseOMatic.java:18: error: cannot find symbolint rand1 =(int)Math.random()*oneLength);method random()  location: class Math
PhraseOMatic.java:19: error: cannot find symbolint rand2 =                                                           (int)(Math.random()*twoLength);symbol:   method random() location: class Math
PhraseOMatic.java:20: error: cannot find symbol int rand3 =(int)Math.random()*threeLength);  symbol:   method random()location: class Math
.\Math.java:4: error: incompatible types: int is not a functional interfaceint y=();
  ^
9 errors

If I run the same code in the online Java IDE it works fine.




Aucun commentaire:

Enregistrer un commentaire