Created
March 1, 2012 04:41
-
-
Save ngnguyen1/1947322 to your computer and use it in GitHub Desktop.
Sắp xếp mảng tăng dần
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.*; | |
class Array | |
{ | |
public static void main(String[] args) | |
{ | |
int n,i,j; | |
int a[]; | |
Scanner input=new Scanner(System.in); | |
System.out.print("Nhap vao so phan tu mang: "); | |
n=input.nextInt(); | |
a=new int[n]; | |
for (i=0;i<n;i++) | |
{ | |
System.out.print("a["+i+"]= "); | |
a[i]=input.nextInt(); | |
} | |
System.out.print("Cac phan tu cua mang da nhap la: "); | |
for (i=0;i<n;i++) | |
{ | |
System.out.print(a[i]+" "); | |
} | |
System.out.println(" "); | |
for (i=0;i<n-1;i++) | |
for (j=i+1;j<n;j++) | |
{ | |
if (a[i]>a[j]) | |
{ | |
int tg=a[i]; | |
a[i]=a[j]; | |
a[j]=tg; | |
} | |
} | |
System.out.print("Mang da nhap lai la: "); | |
for (i=0;i<n;i++) | |
{ | |
System.out.print(a[i]+" "); | |
} | |
System.out.println(" "); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment