• 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:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Program to Access an Array Using a Command-Line Argument

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey everyone. I have this programming assignment with instructions below followed by my code. Will y'all take a look to make sure I'm on the right track? Thanks so much!

INSTRUCTIONS:
Purpose: To learn how to build and access an array.
Write a program that will read in a number from 0 to 25 and spell out that number. The program must also report any values that are out of range.
In other words, I want to type
java Say 22
and see
twenty-two



][/CODE][edit]Add code tags. CR[/edit]

[ November 07, 2008: Message edited by: Campbell Ritchie ]

[ November 07, 2008: Message edited by: Benjamin Chau ]

[ November 07, 2008: Message edited by: Benjamin Chau ]

[ November 07, 2008: Message edited by: Benjamin Chau ]

[ November 07, 2008: Message edited by: Benjamin Chau ]
[ November 07, 2008: Message edited by: Benjamin Chau ]
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you for the e-mail. We have a policy of not answering questions by e-mail; everybody should be able to read the answer. And please maintain indentation with the code button; code is difficult to read without.

So what goes wrong when you try to compile that class? The error message "expected boolean found int" usually means you have used = when you are supposed to use ==. Does anything else go wrong?
And I think it would be better to print "number out of our range" than "invalid entry."
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And what does it say the purpose of the question is?
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And what is the purpose of the loop?

Henry
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I hadn't noticed the loop. Nor had I noticed there are { and } missing, and two ;s missing.
 
Benjamin Chau
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok Campbell, I trimmed it down and edited it per the guidelines. And Henry, you're right - I don't need a loop after all. I wanted to limit the user to only numbers from 0 to 25. In review of the code, I don't need a loop at all, or even an if..else statement. I'll fix my code to reflect this. Is that y'all's thinking also?
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, what happen when you compiled it? You still have to fix the many compile errors.

Henry
 
Benjamin Chau
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Henry,

I'm still having problems compiling. It has something to do with setting my envirornmental path variable correctly. No matter what I try, I can't seem to get it right. Still working on that. Thanks for asking though...

Benjamin
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Benjamin Chau:

I'm still having problems compiling. It has something to do with setting my envirornmental path variable correctly. No matter what I try, I can't seem to get it right. Still working on that. Thanks for asking though...




I would recommend that you don't write another line of code until you get the build environment going. Without this environment, you could be building crap without knowing it.

Henry
 
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Benjamin Chau:
I'm still having problems compiling. It has something to do with setting my envirornmental path variable correctly.


What, EXACTLY, is the text of the compiler error message? That tells you a LOT about what you need to start looking at.

if you get something like

'javac' is not recognized as an internal or external command,
operable program or batch file.


You need to work on your PATH. if you get something like

javac: file not found: fred.java
Usage: javac <options> <source files>
use -help for a list of possible options


it's a problem with you CLASSPATH. Other error can point to problems with your code. There is no way for anyone to help without you telling us what the real problem is.

Even once you get your environment working, I think you need to read the problem again. It specifically says "Purpose: To learn how to build and access an array." I don't see you building an array, although one could argue you are accessing the args[] array. I think if you continue with this algorithm, your instructor will probably mark you down.

But please heed Henry's advice. Get your environment working FIRST, and only then worry about your code.
 
Benjamin Chau
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Fred,

It's the first one:

'javac' is not recognized as an internal or external command,
operable program or batch file.

Others have tried to help me out and I've done as their advice says (change the Environmental Path Variable) but I still can't get it right. I'm running XP Media Edition and here's exactly what I'm doing:

1) I pull up Control Panel then double-click the System icon.

2) I click on the Advanced tab, then the box that reads: Environment Variables.

3) I click the button New under the System variables space and when a box pops up I type in Variable name and the Variable value, using JAVA as the name and the following directory for the value (since that's where the Java software is located on my computer). Here's the exact directory I type in for the Variable value:

C:\Program Files\Java\jre1.5.0_06\bin

4) I repeat the exact same steps as above (3)) for the space that reads: User variables for my name.

5) I open my Command Prompt window and try to compile a program, javac HelloWorld, for instance. Then I get that error message again.

'javac' is not recognized as an internal or external command,
operable program or batch file.

Now when I open up the Command Window and look at the default Path Variable, I see the same directory as always, unchanged, despite all the steps I've taken as described above. Here's the default Path Variable that I see in Command Prompt that never seems to go away:

C:\Documents and Settings\my name>


Any suggestions would be greatly appreciated...

Benjamin
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have answered on your other thread. You may need to reinstall Java.
 
fred rosenberger
lowercase baba
Posts: 13089
67
Chrome Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
have you checked to be sure there really IS a "javac.exe" in that directory?
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Here's the exact directory I type in for the Variable value:

C:\Program Files\Java\jre1.5.0_06\bin



A "JRE", aka Java Runtime Environment, is used for running Java only. It doesn't include a Java compiler.

Henry
 
It's a tiny ad. At least, that's what she said.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic