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; } }
Comments
Leave a comment