Bookmark Topic Watch Topic
  • New Topic

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

 
Aman Kulkarni
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 48381
56
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
    Posts: 48381
    56
    • Mark post as helpful
    • send pies
    • Report post to moderator
    Please continue any discussion here; I am closing this thread as a duplicate of it.
     
    Aman Kulkarni
    Greenhorn
    Posts: 15
    • Mark post as helpful
    • send pies
    • Report post to moderator
    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
    Posts: 6109
    6
    Android IntelliJ IDE Java
    • Mark post as helpful
    • send pies
    • Report post to moderator
    Aman Kulkarni wrote:I used the same program and it executed without any hassles


    False. The code you posted does not compile.
     
    Don't get me started about those stupid light bulbs.
      Bookmark Topic Watch Topic
    • New Topic