37.5k views
2 votes
Write a JAVA program to sort a given array of integers (1 Dimensional) in ascending order (from smallest to largest). You can either get the array as input or hardcode it inside your program.

User Fmsthird
by
7.5k points

1 Answer

2 votes

Answer:

import java.util.Arrays;

public class sort{

public static void main(String []args){

int[] arr = {2,6,9,1,5,3};

int n = arr.length;

Arrays.sort(arr);

for(int i=0;i<n;i++){

System.out.println(arr[i]);

}

}

}

Step-by-step explanation:

first import the library Arrays for using inbuilt functions.

create the main function and define the array with elements.

then, use the inbuilt sort function in java which sort the array in ascending order.

syntax:

Arrays.sort(array_name);

then, use for loop for printing the each sorting element on the screen.

User FelixSFD
by
8.4k points