import java.util.*;
import java.io.*;
public class ArregloADPlus{
double AAD[] = new double[30];
double copiaAAD[] = new double[30];
double resp, temp2;
int modo, MDC, c1=0;
Scanner tecla
= new Scanner
(System.
in); public static final String CENTINELA
= "fin";
void inicio(){
System.
out.
println("Arreglo para ordenar ascendente o descendentemente los valores ingresados"); }
void menu(){
ArregloADPlus AADP = new ArregloADPlus();
System.
out.
println("Ingrese 1 para modo ascendente o 2 para modo descendente"); modo = tecla.nextInt();
if (modo !=1 && modo !=2){
System.
out.
println("Ingrese 1 o 2"); AADP.menu();}
System.
out.
println("Ingrese como desea introducir los valores"); System.
out.
println(" 1)Lectura Por teclado n 2)Por Omisionn 3)Lectura De Archivon 4)Aleatorion"); MDC = tecla.nextInt();
}
ArregloADPlus AADP = new ArregloADPlus();
switch(MDC){
case 1: AADP.teclado();
break;
case 2: AADP.omision();
break;
case 3: AADP.archivo();
break;
case 4: AADP.aleatorio();
break;
default:{
if (MDC<0 || MDC>4)
System.
out.
print("ingrese un valor de 1 al 4n");} }
}
System.
out.
println("Ingrese un valor o "fin
" para terminar"); temp = entrada.readLine();
while(!temp.equals(CENTINELA)){
resp
= Double.
parseDouble(temp
); AAD[c1++] = resp;
System.
out.
println("Ingrese una valor o "fin
" para terminar"); temp = entrada.readLine();}
System.
arraycopy(AAD,
0,copiaAAD,
0,AAD.
length); }
void omision(){
double AAD1[] = {-26.4,12.6,15,24,78.91,.369,74,14,.1248,7845,6941,1.257425,100,964,-1.36,15485,1000,7895,.137,-9784,4597,12,64,7461,.100,3.14,79.01,963.12,20,457.1};
System.
arraycopy(AAD1,
0,AAD,
0,AAD1.
length); System.
arraycopy(AAD1,
0,copiaAAD,
0,AAD1.
length); }
double archivo() {
int i=0;
Scanner sc
=new Scanner
(System.
in); System.
out.
print("Ingrese la ruta del archivo:"); file=sc.nextLine();
System.
out.
println("Leyendo del archivo:"+file
); if(!file.equals("")) {
try {
Scanner in
=new Scanner
(new File(file
)); while(in.hasNextLine()) {
s=in.nextLine();
AAD
[i
++]=Double.
parseDouble(s
); System.
out.
print(", "+AAD
[i
-1]);} System.
arraycopy(AAD,
0,copiaAAD,
0,AAD.
length); in.close();
}
}
else
System.
out.
println("no se pudo abrir el archivo"+file
); return i;
}
void aleatorio(){
for(int c3=0;c3<AAD.length;c3++){
int tmp
=Math.
round((float)Math.
random()*1000%37767
); AAD[c3]=(double)tmp;}
System.
arraycopy(AAD,
0,copiaAAD,
0,AAD.
length); }
void calcula(){
if (modo == 1){
else{
int i,j;
for(i=0,j=AAD.length -1; i<AAD.length/2;i++,j--){
temp2=AAD[i];
AAD[i]=AAD[j];
AAD[j]=temp2;}
}
}
void resultados(){
System.
out.
println("nnLos valores ingresados son:"); for(int c5=0; c5<AAD.length; c5++){
System.
out.
print(copiaAAD
[c5
]+", ");} System.
out.
println("nnLos valores ingresados ordenados son:"); for(int c5=0; c5<AAD.length; c5++){
System.
out.
print(AAD
[c5
]+", ");} }
ArregloADPlus AADP = new ArregloADPlus();
int r='S';
AADP.inicio();
while (r=='s' || r=='S'){
AADP.menu();
AADP.modoCaptura();
AADP.calcula();
AADP.resultados();
System.
out.
println("nnDesea Ordenar otros elementos s/n"); }
}