Answer to Question #58606 in Java | JSP | JSF for NOUR

Question #58606
Write a public static method that takes 3 integer numbers and return a string
that has the three numbers separated by a space and sorted in descending order.
1
Expert's answer
2016-03-22T11:35:04-0400
package test;


public class Sort {
public static void main(String[] args) {
System.out.println(sort(4, 3, 5));
}
public static String sort(int a, int b, int c) {
int tmp;
if (a < b) {
tmp = a;
a = b;
b = tmp;
}
if (b < c) {
tmp = b;
b = c;
c = tmp;
}
if (a < b) {
tmp = a;
a = b;
b = tmp;
}
return a + " " + b + " " + c;
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS