• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

assignment 1 solution: I don't understand

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't understand why instructor put
if (arg.length==1)
{
....
}
else
....
what if someone entered more than 1 word? so it is invalid?
 
tumbleweed
Posts: 5089
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The instructor is checking that only one number is entered.
If you entered more than one number the else clause will be executed.
 
Sheriff
Posts: 9109
12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
We want you to assume only one name from the command line.
One of the rules of the cattle drive is don't add extra stuff unless specifically mentioned. It just makes more work for us.
 
Ranch Hand
Posts: 233
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Us greenhorns have to read the assignments VERY carefully.
It says: "Except a value from the command line and print it to the screen one hundred times".
It expects a single value not multiple values to be entered, so the solution checks for a args array length of one. Also read the message printed out if more or less than one argument is entered - else { ..."Usage:...".
I too questioned the limited scope of the condition statement in the solution. However after reading the assignment more closely I realized that only one argument was ever expected to be passed. Why do more than the assignment requires.
 
reply
    Bookmark Topic Watch Topic
  • New Topic