In: Computer Science
Using the Math.max() and Math.min() functions (along with whatever else you've been taught in lecture so far) write a function that accepts three integers and prints them in either ascending or descending order.
Starter code for this function is included below, though you are welcome to write it from scratch:
public class Main { public static void main( String[] args ) { sortInts( 321, 654, 987 ); } int highVal; // HH int midVal; // MM int lowVal; // SS <TODO> - Implement this function> System.out.println( highVal + " " + midVal + " " + lowVal ); } }
|
public class Main {
public static void main( String[] args ) {
sortInts( 4321, 654, 987 );
}
public static void sortInts( int arg1, int arg2, int arg3 ) {
int lowVal=arg1; // HH
int midVal=arg2; // MM
int highVal=arg3; // SS
if(lowVal>midVal) {
int temp=lowVal;
lowVal=midVal;
midVal=temp;
}
if(midVal>highVal) {
int temp=midVal;
midVal=highVal;
highVal=temp;
}
if(lowVal>midVal) {
int temp=lowVal;
lowVal=midVal;
midVal=temp;
}
System.out.println( lowVal + " " + midVal + " " + highVal );
}
}
NOTE : PLEASE COMMENT BELOW IF YOU HAVE CONCERNS.
I AM HERE TO HELP YOUIF YOU LIKE MY ANSWER PLEASE RATE AND HELP ME IT IS VERY IMP FOR ME