0% found this document useful (0 votes)
4 views

5.2 Sorting Array in Java

Uploaded by

mrnirajbro
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

5.2 Sorting Array in Java

Uploaded by

mrnirajbro
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

import java.util.

Scanner;

public class Array {

public static void main(String args[]) {

Scanner sc = new Scanner(System.in);

int a[] = new int[10];

int i,j;

System.out.println("Enter the elements of the array:");

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

a[i] = sc.nextInt();

//Bubble Sort

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

for ( j = i+1 ; j < n; j++) {

if (a[i] > a[j]) {

int t = a[i];

a[i] = a[j];

a[j] = t;

System.out.println("Sorted Array:");

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

System.out.print(a[i] + " ");

}
}

You might also like