Problema con el Ordenamiento
Sucede que que genera un random especificado de 0 a 1000 todo va bien pero no hace el ordenamiento;a menos que le quite el random e ingrese manualmente los datos en este caso los numeros del 0 hasta el 1000 en el "randomNumbers.txt"solo asi realiza el ordenamiento pero lo que no quiero es estar ingresando 1000 o 10000 numeros y si copio y pego los numeros tampo lo realiza tiene que ser obligatorio estar tecleandolos directamente en el .txt "randomNumbers.txt"
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Mictlan-Netza
*/
import java.io.*;
import java.util.ArrayList;
import java.util.InputMismatchException;
import java.util.Random;
import java.util.Scanner;
import javax.swing.JOptionPane;
public class MezclaDirecta{
int Particion=1;
int NumBloc=100;
int Itera=1;
public static void main(String arg[]) throws IOException{
FileReader Arch = new FileReader("randomNumbers.txt");
PrintWriter out = new PrintWriter("randomNumbers.txt");
BufferedReader br = new BufferedReader(Arch);
ArrayList numeros = new ArrayList();
long tiempoInicial = System.currentTimeMillis();
int totalRandom = 100;///cuantos va a sacar
Random generarRandom = new Random();
char [] arreglo = new char[totalRandom];
for (int i = totalRandom; i >=1; i--)
{
out.println(generarRandom.nextInt(100)+" ");///rango en que los va aimprimir
}
out.close();
br.close();
int opcion;
String op2=null;
boolean err=true;
MezclaDirecta m=new MezclaDirecta();
while (err==true){
Scanner Teclado = new Scanner(System.in);
Scanner Teclado2 = new Scanner(System.in);
JOptionPane.showMessageDialog(null, "Metodo Mezcla Directa \t\t"+"\nInicializado con 15 Numeros "+"\nPuede insertar nuevos numeros en 'ArhivoNumeros.TXT' para una nueva ordenacion");
System.out.println ("1) Iniciar Metodo");
System.out.println ("2) salir");
System.out.println (":::::::::::::::::::::::::::::::::::");
System.out.println ("Opcion:");
try{
opcion = Teclado.nextInt();
switch (opcion) {
case 1:
{
m.Mezcla();
JOptionPane.showMessageDialog(null, "Tambien puede vizualizar el ordenamiento en el bloc de notas 'ArchivoNumeros.TXT'");
}
break;
case 2:
JOptionPane.showMessageDialog(null, "#Estructura de Datos 20122#"+"\nIng.Sistemas Computacionales"+"\nNetzahualcoyotl Lopez Lopez");
System.exit(0);
err=false;
break;
default :
JOptionPane.showMessageDialog(null, "\"No existe opcion Introducida;Intente de nuevo opciones de 1-02");
}
}catch (InputMismatchException inputMismatchException) {
System.err.printf("\n PRESIONE (ENTER)PARA INTENTAR DE NUEVO\n");
System.err.printf("\n No se admiten caracteres: %s\n",inputMismatchException);
op2=Teclado2.nextLine();
}
}
}
- Inicie sesión o regístrese para enviar comentarios
Problema con el Ordenamiento 2ª parte
public void Mezcla(){
while(Particion
Pon el código completo
Puedes usar las etiquetas < code > aqui tu código
Exise un método llamado sort(arreglo) que te puede servir:
class Main{
public static void main(String ... args){
int[] arreglo={32,0,45,7,89,21,55,31};
Arrays.sort(arreglo);
for(int e: arreglo){
System.out.println(e);
}
}
}
Este código muestra como ordenar un arreglo.