Ask 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 the array as input or hardcode it inside your program.

+4
Answers (1)
  1. 25 June, 03:39
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers