Ask Question
10 December, 23:52

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.

+3
Answers (1)
  1. 11 December, 00:09
    0
    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
    System. out. println (arr[i]);

    }

    }

    }

    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.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Write a JAVA program to sort a given array of integers (1 Dimensional) in ascending order (from smallest to largest). You can either get ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers