mang java
import java.util.Scanner;
public class mang {
public static void main(String[] args) {
int n;
int[] arr;
int i,j,k;
int temp;
Scanner scan=new Scanner(System.in);
System.out.println("So phan tu:");
n=scan.nextInt();
arr=new int[n];
for(i=0;i<n;i++){ System.out.println("Phan tu thu "+(i+1)); arr[i]=scan.nextInt();
}
int type=0;
do{
System.out.println("1.Tang dan");
System.out.println("2.Giam dan");
type=scan.nextInt();
}
while(type!=1&&type!=2);
switch(type){
case 1:{
for(j=0;j<n;j++)for(k=j;k<n;k++) if(arr[j]>arr[k])
{
temp=arr[j];
arr[j]=arr[k];
arr[k]=temp;
}
}
break;
case 2:{
for(j=0;j<n;j++) for(k=j;k<n;k++) if(arr[j]<arr[k]){
temp=arr[j];
arr[j]=arr[k];
arr[k]=temp;
}
}
}
for(i=0;i<n;i++) System.out.print(arr[i]+" ");
}
}
Bạn đang đọc truyện trên: Truyen247.Pro