elhacker.net cabecera Bienvenido(a), Visitante. Por favor Ingresar o Registrarse
¿Perdiste tu email de activación?.

 

 


Tema destacado: ¿Eres nuevo? ¿Tienes dudas acerca del funcionamiento de la comunidad? Lee las Reglas Generales


  Mostrar Mensajes
Páginas: [1] 2
1  Programación / Java / Re: Problema con Threads en Java en: 23 Septiembre 2013, 10:46 am
muchas gracias M1τѕυ era parte de mi problema eso que me mencionas agradezco que me hayas ayudado y gracias a corregir eso y otras cosillas pude hacerlo funcionar. Saludos :D
2  Programación / Java / Problema con Threads en Java en: 18 Septiembre 2013, 08:51 am
Que tal buenos dias, quisiera ver si me podrian ayudar con mi programa, lo que pasa es que lo estoy haciendo con Threads pero cuando entra al metodo run no ejecuta el metodo de ordenamiento. El programa tiene que hacer el ordenamiento Burbuja de 25000 numero generados aleatoriamente por medio de Threads, hice que funcionara sin Threads pero cuando lo hago por medio de Hilos no se ejecuta la funcion de ordenamientos y la verdad no se por que (cabe mencionar que sin hilos funciona a la perfeccion), pero con hilos me sale el siguiente error. Espero me puedan ayudar.

Saludos.

Exception in thread "Thread-0" java.lang.NullPointerException
   at ordenamientos.Bubble.bubble_sort(Bubble.java:52)
   at ordenamientos.Bubble.run(Bubble.java:38)
   at java.lang.Thread.run(Thread.java:724)


Este es el codigo de mi programa.


package ordenamientos;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

public class Bubble implements Runnable
{
   Thread t;
   public int [] matrix;
   
   final void setMatriz(int matriz[])
   {
      matrix = matriz;
   }
   
   int[] getMatriz()
   {
      return matrix;
   }
   
   public Bubble()
   {
   }
   
   public Bubble(int matriz[])
   {
      matrix = matriz;
      
   }
   
   public void run()
   {
      System.out.println("Aqui deberia estar corriendo el ordenamiento burbuja :/");
      bubble_sort(getMatriz());
      
   }
   
   public void bubble_sort(int matriz[])
   {
      long comienza = System.currentTimeMillis();
      int buffer;
      int i,j;
      
      for(i = 0; i < 25000; i++)
      {
         for(j = 0; j < i; j++)
         {
            if(matriz < matriz [j])
            {
               buffer = matriz[j];
               matriz[j] = matriz;
               matriz = buffer;
            }
         }
         
      }
      
      for(int x = 0; x < matriz.length; x++)
      {
         System.out.println("Numeros: " + matriz
  • );
      }
      long termina = System.currentTimeMillis();
      long tiempoTranscurrido = termina - comienza;
      System.out.println("\n\nTiempo transcurrido con el metodo de ordenamiento Burbuja: " + tiempoTranscurrido + " milisegundos");
      
          try
          {
             File TextFile = new File("/home/norochii/workspace/Ordenamientos/Tiempos.odt");
             FileWriter TextOut = new FileWriter(TextFile, true);
             TextOut.write ("Ordenamiento Burbuja: "+tiempoTranscurrido + " Milisegundos"+"\r\n");
             TextOut.close();
          }
          catch(IOException e)
          {   
               System.out.println("Error!!");       
          }
   }

}




package ordenamientos;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
import java.util.Random;
import ordenamientos.Bubble;

public class Principal
{   
   public static void main(String[] args)
   {
      int [] arreglo;
      arreglo = new int [25000];
      
      Shell shell = new Shell();
      Bubble burbuja = new Bubble();
      Insercion insercion = new Insercion();
      
      @SuppressWarnings("resource")
      Scanner entrada = new Scanner(System.in);
      Random numero_aleatorio = new Random();
      
      if(burbuja.matrix == shell.matrix && burbuja.matrix == insercion.matrix )
      {
         if(shell.matrix == burbuja.matrix && shell.matrix == insercion.matrix)
         {
            if(insercion.matrix == burbuja.matrix && insercion.matrix == shell.matrix)
            {
               System.out.println("Datos: " );
               for(int x = 0; x<arreglo.length; x++)
               {
                  int valor;
                  valor = numero_aleatorio.nextInt(250000);
                  arreglo
  • = valor;
                  System.out.println(valor);
                  
                  try
                     {
                         File TextFile = new File("/home/norochii/workspace/Ordenamientos/Numeros sin Ordenar.odt");
                         FileWriter TextOut = new FileWriter(TextFile, true);
                         TextOut.write (valor +"\r\n");
                         TextOut.close();
                     }
                     catch(IOException e)
                     {
                           System.out.println("Error!!");   
                     }
                  
                  
               }
               
               System.out.println("\n\nGeneracion de numeros aleatorios lista.");
               System.out.print("Presiona cualquier tecla para continuar: ");
               entrada.nextLine();
               System.out.println("\n\n\n\n");
               
               
               System.out.println("Ordenamiento Shell: ");
               System.out.println("\n\n\n\n\n\n");
               shell.shell_sort(arreglo);
               try {
                  Thread.sleep(4000);
               } catch (InterruptedException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
               }
               
               
               System.out.println("\n\n\n\n");
               System.out.println("Ordenamiento Burbuja: ");
               System.out.println("\n\n\n\n\n\n");
               //burbuja.bubble_sort(arreglo);
               
               Thread hilo = new Thread(burbuja);
               hilo.start();
               
               //new Thread(burbuja).start();
               try {
                  Thread.sleep(4000);
               } catch (InterruptedException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
               }
               System.out.println("Ordenamiento Insercion: ");
               insercion.insercion_sort(arreglo);
      
            
               System.out.println("\n\n\n\n\n\n");
               
               
               
            }
         }
      }
   }

}


3  Sistemas Operativos / GNU/Linux / Re: Grub rescue> [SOLUCIONADO] en: 22 Abril 2012, 18:23 pm
hahaha gracias!!! te amo!!! me salvaste la vida :'( eres el mejor de los mejores :'( muchas gracias estare eternamente agradecido :3
4  Programación / Programación C/C++ / Re: Ayuda para crear un socket en C en: 5 Noviembre 2011, 07:48 am
gracias n_n
5  Programación / Programación C/C++ / Ayuda para crear un socket en C en: 5 Noviembre 2011, 02:15 am
Hola! necesito hacer un socket alguien que me pueda recomendar algun material para saber como hacer, un socket desde cero  sinceramente no se nada de sockets, pero si se de c y c++y la verdad si me gustaria aprender a hacer uno... porfas se los agradeceria mucho :3
6  Programación / Programación C/C++ / Re: Ayuda!!! :( con c++ en: 19 Octubre 2011, 21:56 pm
Muchisimas Gracias Me ayudo de mucho si funciona muy bien te lo agradezco :D n.n espero poder contar con tu ayuda si es que me trabo en algo mas :D .
Nos vemos
Saludos
Gracias
7  Programación / Programación C/C++ / Re: Ayuda!!! :( con c++ en: 19 Octubre 2011, 17:19 pm
ia corriste el programa con las modificaciones que isiste?? :O es k has de cuenta k se supone k si el usuario mete una letra en vez de numero debe aparecer el letrero de numero invalido i volver a visualizar donde se ingresa el numero pero.... no se si en tu compilador si haga eso las modificaciones k le isiste por k ami no :'( lo siento por dar tantos problemas pero es k e buskado pero nomas no encuentro u.u
8  Programación / Programación C/C++ / Re: Ayuda!!! :( con c++ en: 19 Octubre 2011, 16:53 pm
para que sirve esta linea??
stringstream numero(entrada);
:O
9  Programación / Programación C/C++ / Re: Ayuda!!! :( con c++ en: 19 Octubre 2011, 16:00 pm
no sirvio u.u :'(
10  Programación / Programación C/C++ / Ayuda!!! :( con c++ en: 19 Octubre 2011, 15:29 pm
hello.. tengo una duda.. estoy haciendo un programa en c++ y necesito saber como hacerle para que cuando el usuario introduzca un caracter en la variable entera entre de nuevo al ciclo do-while por que lo que hace el programa cuando introducen un caracter es k despliega la tabla del cero y no se devuelve al ciclo do-while el codigo es el siguiente :D les agradeceria su ayuda :D

#include "stdafx.h"
#include <iostream>
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#include <Windows.h>


using namespace std;

void TablasDeMultiplicar()
{
   int Tabla = 0;
   do
   {
   cout<<"\n\n  Ingresa el numero de la Tabla de Multiplicar que quieras Aprender: \n\n";
   cout<<"  Solo Podras Ver las Tablas del 0 al 12\n\n";
   cout<<"  Tabla del : ";
   cin>>Tabla;
   if(Tabla<=12 && Tabla >=0)
   {
   
   for(int i = 0; i<=12; i++)
   {
      cout<<"\n"<<Tabla<<" X "<<i<<" = "<<Tabla*i<<endl;
   }
   cout<<"\n\n\n"<<endl;
   }
   else
   {
      cout<<"\n\nNumero no valido"<<endl;
   }
   cout<<"\n\n\n";
   system("PAUSE");
   system("cls");
   }while(Tabla>12 || Tabla <0 );
}
int main()
{
   char a;
   system("color 9B");

   TablasDeMultiplicar();
   
   system("PAUSE");
   return 0;
}
Páginas: [1] 2
WAP2 - Aviso Legal - Powered by SMF 1.1.21 | SMF © 2006-2008, Simple Machines