Question

Write a Java method called compare that takes two integers as input parameters and returns 1...

Write a Java method called compare that takes two integers as input parameters and returns 1 if the first parameter is larger than the second parameter returns – 1 if the second parameter is larger than the first parameter, and returns 0 if the two parameters are equal.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Here is the code for the function asked.

Code:

public static int compare(int x,int y){

if(x>y)return 1;

else if(y>x) return -1;

else if(x==y) return 0;

return 0;

}

Sample Run:

you can see the output on the left side

ht Main.java @ saved 1 class Main { //compare that takes two integers as input parameters public static int compare(int x, in

Add a comment
Know the answer?
Add Answer to:
Write a Java method called compare that takes two integers as input parameters and returns 1...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT