Ask Question
7 August, 21:31

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. 7 August, 23:11
    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?
Find 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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers