Advertisement
Kyrexar

Emparejador

Mar 14th, 2013
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.29 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. public class emparejador
  4. {
  5.     static Scanner teclado = new Scanner(System.in);
  6.    
  7.     public static int[] vector_aleatorio( int tamaño )
  8.     {
  9.         int[] v = new int[tamaño];
  10.        
  11.         for( int i=0 ; i<tamaño ; i++ )
  12.         {
  13.             v[i] = i;
  14.         }
  15.        
  16.         for( int i=0 ; i<tamaño ; i++ )
  17.         {
  18.             int j = (int) (Math.random()*tamaño);
  19.            
  20.             int aux=v[j];
  21.             v[j]=v[i];
  22.             v[i]=aux;
  23.         }
  24.        
  25.         return v;
  26.     }
  27.    
  28.     public static void main( String [] args )
  29.     {
  30.         System.out.println( " Introduce cuantos jugadores: " );
  31.         int jugadores = teclado.nextInt();
  32.        
  33.         System.out.println( " En grupos de: " );
  34.         int grupos = teclado.nextInt();
  35.        
  36.         String[] nombres = new String[jugadores];
  37.         for( int i=0 ; i<jugadores ; i++ )
  38.         {
  39.             System.out.println( " Introduce otro nombre: " );
  40.             nombres[i] = teclado.nextLine();
  41.         }
  42.        
  43.         int orden[]=vector_aleatorio(jugadores);
  44.         for( int i=0 ; i<jugadores ; i++ )
  45.         {
  46.             System.out.println( nombres[orden[i]] );
  47.             if( (i+1)%grupos==0 ) System.out.println( "---" );
  48.         }
  49.     }
  50. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement