SCHOOL OF CODE BUILDERS
Learn To CODE. Become A DEVELOPER.
Pages
HOME
DATA STRUCTURES
STRINGS
ARRAYS
MATRIX
BINARY TREES
LINKED LIST
STACK
QUEUE
SORTING
SEARCHING
C
PYTHON
PSEUDOCODE
CONTEST PROBLEMS
ALGORITHMS
PATTERNS
PHP
C PUZZLES
C INTERVIEW QUESTIONS
JAVA
C++
HASHING
RECURSION
BASIC C PROGRAMS
TCS-CODEVITA
FACEBOOK
CONTACT US
Java program to sort an array
Java program to sort an array
Output:
Enter the number of elements to sort: 10
Enter the numbers to sort:
10 9 8 7 6 5 4 3 2 1
The Sorted Array is:
1 2 3 4 5 6 7 8 9 10
Implementation:
import java.util.*; import java.lang.*; import java.io.*; class CodeRegister { public static void sortArray(int[] array) { int n=array.length; for(int i=0;i
array[j]) { swapPair(array,i,j); } } } } public static void swapPair(int[] array,int i,int j) { int temp; temp=array[i]; array[i]=array[j]; array[j]=temp; } public static void main (String[] args) throws java.lang.Exception { Scanner in = new Scanner(System.in); int[] array; int n; System.out.println("Enter the number of elements to sort:"); n = in.nextInt(); array = new int[n]; System.out.println("Enter the numbers to sort:"); for(int i=0;i
PREVIOUS
NEXT
HOME