# How to get my code to display the numbers entered from least to greatest

I am having trouble getting the numbers to go in ascending order from least to greatest.

Enter first integer:6
Enter first integer:1
Enter first integer:5

Case (2)
Enter first integer:9
Enter first integer:7
Enter first integer:2

This is my code

``````import java.util.Scanner;

public class AscendingOrder
{
public static void main(String [] args)
{
Scanner input = new Scanner(System.in);

System.out.print("Enter first integer: ");
int number1 = input.nextInt();

System.out.print("Enter second integer: ");
int number2 = input.nextInt();

System.out.print("Enter third integer: ");
int number3 = input.nextInt();

System.out.println("Order ascending: " + number1 + ", " + number2 + " ," + number3);

int temp;
if(number2 < number1 || number3 < number1)

{

if(number2 < number1)
{
temp = number1;
number1 = number2;
number2 = temp;
}
if (number3 < number1)
{
temp = number1;
number1 = number3;
number3 = temp;
}
if (number3 < number2)
{
temp = number2;
number2 = number3;
number3 = temp;
}

}
}
}

``````

### >Solution :

If you really want to sort manually:

``````public static void main(String[] args) {
Scanner input = new Scanner(System.in);

System.out.print("Enter first integer: ");
int number1 = input.nextInt();

System.out.print("Enter second integer: ");
int number2 = input.nextInt();

System.out.print("Enter third integer: ");
int number3 = input.nextInt();

int smallest, middle, largest;

if (number1 <= number2 && number1 <= number3) {
smallest = number1;
if (number2 <= number3) {
middle = number2;
largest = number3;
} else {
middle = number3;
largest = number2;
}
} else if (number2 <= number1 && number2 <= number3) {
smallest = number2;
if (number1 <= number3) {
middle = number1;
largest = number3;
} else {
middle = number3;
largest = number1;
}
} else {
smallest = number3;
if (number1 <= number2) {
middle = number1;
largest = number2;
} else {
middle = number2;
largest = number1;
}
}

System.out.println("Sorted integers: " + smallest + ", " + middle + ", " + largest);
}

``````

However, the much simpler solution will be to put the values into an array list and then simply sort them using the Collections.sort method:

``````public static void main(String[] args) {
Scanner input = new Scanner(System.in);

ArrayList<Integer> numbers = new ArrayList<>();
System.out.print("Enter first integer: ");