In: Computer Science
Write a class that asks a user to enter three integers. Display them in ascending and descending order. Save the file as Sorting.java
Again, Don’t forget to create the application/project SortingTest.java Class that has the main method and an object to use the Sorting class.
class Sorting{
private int num1;
private int num2;
private int num3;
public Sorting(int aA, int aB, int aC) {
num1 = aA;
num2 = aB;
num3 = aC;
if(num1>num2) {
int
temp=num1;
num1=num2;
num2=temp;
}
if(num2>num3) {
int
temp=num2;
num2=num3;
num3=temp;
}
if(num1>num2) {
int
temp=num1;
num1=num2;
num2=temp;
}
}
public String toString() {
return "Ascending: "+num1+"
"+num2+" "+num3+"\nDescending: "+num3+" "+num2+" "+num1;
}
}
public class SortingTest {
public static void main(String[] args) {
Sorting s = new Sorting(10, 3,
12);
System.out.println(s);
}
}
Note : Please comment below if you have concerns. I am here to help you
If you like my answer please rate and help me it is very Imp for me