Java Help, Please...

Status
Not open for further replies.

nicole

Seniorius Lurkius
1
I'm in a beginning Java class and I have to write this program and I'm completely stuck. I have to use JBuilder 5 to do it. If anyone could give me a few pointers, I'd really appreciate it.

The program has to read integers from the command line, print the integers in reverse order, and compute the total of all the integers. I know that I need to find the length of the array and somehow print out from the length backwards to print out the integers on the command line and then convert the strings of that array to ints and add those, but I have no idea how to do it. I pretty much know what it is that I have to do, I just don't know how to make it all work. I'm really stuck.

Please help!!! Thanks!!!
 

Malyk

Ars Tribunus Angusticlavius
8,558
Subscriptor
This really reaks of a "do my homework for me" post, but I'll give you a few pointers.

First, the main method takes one parameter; that being an array of strings that were entered on the command line. So you'll want to access the items in that array to find the numbers you'll be adding.

Second, every array has a .length() method, so that will tell you the length of the array.

Third, look into the Integer class. One of it's constructors takes a string and makes it into an integer.

Fourth, you'll want to use a for loop to move through the array backwards printing out the numbers and adding them to another variable for the total.

To recap, look at the main methods parameters, the .length method of arrays, the Integer class constructors, and finally for loops.

Should be pretty easy once you understand how to use all of those things.

Mike
 

MooseAreFun

Ars Legatus Legionis
10,827
Subscriptor
I don't know JBuilder, but most IDE's have a new program wizard that will create basic program outlines for you.

Find a good book and/or online Java turorial, and look for;
- System.out.blah to write to the console.
- Using Integers and Arrays.
- For loops.

I've found "Sams - Tech Yourself Java 2 in 21 days" by Laura Lemay and Rogers Cadenhead quite helpful and well written.

Also check the Java API at http://java.sun.com/j2se/1.3/docs/api/index.html
trying to be helpful without doing it myself.... :)
 
Status
Not open for further replies.