The ascending order was displaying the same as descending order. how do i get the ascending order to be different from descending order?

public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n =10;
int a[] = new int[n];
System.out.println("Enter all the elements:");
for (int i = 0; i < n; i++){
a[i] = in.nextInt();
}

for (int i = 0; i < n; i++){
for (int j = i + 1; j < n; j++){
if (a[i] < a[j]) {
int temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
System.out.println("Descending Order:");
for (int i = 0; i < n; i++){
System.out.print(a[i]+",");
}

for (int i = 0; i < n; i++){
for (int j = i + 1; j < n; j++){
if (a[i] > a[j]) {
int temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}
System.out.println("\nAscending Order:");
for (int i = 0; i < n; i++){
System.out.print(a[i]+",");
}
}

Which one is wrong and which one is right? This will help us focus on only the relevant code.

the ascending order is the same as descending order.

To get the ascending order to be different from the descending order, you need to modify the sorting algorithm.

In the provided code, the descending order is achieved by swapping elements if the current element is less than the next element. To obtain the ascending order, you need to modify this condition to swap elements if the current element is greater than the next element.

Here's the modified code:

```java
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = 10;
int a[] = new int[n];

System.out.println("Enter all the elements:");
for (int i = 0; i < n; i++){
a[i] = in.nextInt();
}

// Descending order
for (int i = 0; i < n; i++){
for (int j = i + 1; j < n; j++){
if (a[i] < a[j]) {
int temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}

System.out.println("Descending Order:");
for (int i = 0; i < n; i++){
System.out.print(a[i]+", ");
}

// Ascending order
for (int i = 0; i < n; i++){
for (int j = i + 1; j < n; j++){
if (a[i] > a[j]) {
int temp = a[i];
a[i] = a[j];
a[j] = temp;
}
}
}

System.out.println("\nAscending Order:");
for (int i = 0; i < n; i++){
System.out.print(a[i]+", ");
}
}
```

Now, the ascending order will be displayed as different from the descending order.