wood burning stoves 2.0*
The moose likes Beginning Java and the fly likes The correct version of the Phrase-O-Matic (ref: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
Reply locked New topic
Author

The correct version of the Phrase-O-Matic (ref:Head First Java)

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...
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 39478
    
  28
Aman Kulkarni wrote: . . . This program is 100% error-free and will give correct output...
100% error-free: that is a red rag to a bull indeed!
  • 1: incorrect indentation, using tabs rather than spaces.
  • 2: Incorrect formatting, not using space after comma.
  • 3: Incorrect typing, using [] after args rather than before it.
  • 4: Poor formatting: no spaces adjacent to binary operators.
  • 6: PhraseOMatic misspelt in name of class.
  • 6: Compiler error: dangling quote at the end of a line. That is obscured because you didn’t use the code button.
  • 7: Similar error where a String literal is split over two lines.
  • 8: additional new lines where they are not required, and lines crammed together as a block where new lines would have been useful.
  • 9: Lines too long.
  • Never have the arrogance to say you are 100% error-free. I got 58 compiler errors when I copied and pasted your code.
    Campbell Ritchie
    Sheriff

    Joined: Oct 13, 2005
    Posts: 39478
        
      28
    Please continue any discussion here; I am closing this thread as a duplicate of it.
    Aman Kulkarni
    Greenhorn

    Joined: Jan 21, 2012
    Posts: 15
    I used the same program and it executed without any hassles...I accept the class name and the indentation mistake....and the String args[] is the way we were taught java...it may be considered as my ignorance but not arrogance
    Jeff Verdegan
    Bartender

    Joined: Jan 03, 2004
    Posts: 6109
        
        6

    Aman Kulkarni wrote:I used the same program and it executed without any hassles


    False. The code you posted does not compile.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: The correct version of the Phrase-O-Matic (ref:Head First Java)