This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes integer  parameters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "integer  parameters" Watch "integer  parameters" New topic
Author

integer parameters

jessie mccarty
Greenhorn

Joined: Dec 03, 2005
Posts: 8
I need help, can somebody help me witht his problem..like give me some basic idea of how to start this prgram..Im really new in java and i really need any suggestions ...

i need to write a program that takes 2 integer parameters and returns the intger value with the largest value..


thanks much...Im not looking for the exact code just a hint or how to start this and from that ill continue the code...
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by jessie mccarty:
... i need to write a program that takes 2 integer parameters and returns the intger value with the largest value...

So that means you've got a method that takes 2 int arguments, then returns one of these based on some calculation, right? Can you show us your code so far?

(Note: There's already a method in java.lang.Math that does this, but I'm guessing this is an assignment to write your own...)


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Adam Price
Ranch Hand

Joined: Nov 11, 2005
Posts: 95
Also a greenhorn, but I would say that you should make a method with a return type "int" and two arguments "a" and "b"
Then an if-else structure to decide which to return

(I.E. Here is a program to decide which of two strings is longer and return it:



Addl' thoughts:

I haven't dealt with the case wherein the two strings are the same length. I would do it with if....else if....else
[ December 13, 2005: Message edited by: Adam Price ]
Ken Blair
Ranch Hand

Joined: Jul 15, 2003
Posts: 1078
A hint? Given int a and int b you can find the larger with the expression if (a > b ) { // do something } else { // do something else }.
jessie mccarty
Greenhorn

Joined: Dec 03, 2005
Posts: 8
Hi thanks for all your reply, i tried coding and i think im getting it but Im getting the opposite result, instead of the biggest integer, its giving me the smallest intger first..



what am i doing wrong?

thanks
Greg Charles
Sheriff

Joined: Oct 01, 2001
Posts: 2854
    
  11

Woof! Where to start? Why pass an array to compare two integers? Why the double loop? What you want to do is be able to state clearly in English how you would solve the problem. If you can get your thinking clear, you will have an easier time putting it into code.

That said, look at:


max means largest, but the comment says smallest. Of course, Java doesn't care, because you can name your variables anything you want. However, it shows some confusion on your part, which in this case has resulted in wrong code.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

That's certainly an "A" for effort.
Adam Price
Ranch Hand

Joined: Nov 11, 2005
Posts: 95


what am i doing wrong?
[/qb]


Note that technically, this method doesn't return anything - it prints something to the console. To get a return, you would declare a return type:

and replace your System.out.println's with return

The you could call it like this

[ January 02, 2006: Message edited by: Adam Price ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: integer parameters