Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class emparejador
- {
- static Scanner teclado = new Scanner(System.in);
- public static int[] vector_aleatorio( int tamaño )
- {
- int[] v = new int[tamaño];
- for( int i=0 ; i<tamaño ; i++ )
- {
- v[i] = i;
- }
- for( int i=0 ; i<tamaño ; i++ )
- {
- int j = (int) (Math.random()*tamaño);
- int aux=v[j];
- v[j]=v[i];
- v[i]=aux;
- }
- return v;
- }
- public static void main( String [] args )
- {
- System.out.println( " Introduce cuantos jugadores: " );
- int jugadores = teclado.nextInt();
- System.out.println( " En grupos de: " );
- int grupos = teclado.nextInt();
- String[] nombres = new String[jugadores];
- for( int i=0 ; i<jugadores ; i++ )
- {
- System.out.println( " Introduce otro nombre: " );
- nombres[i] = teclado.nextLine();
- }
- int orden[]=vector_aleatorio(jugadores);
- for( int i=0 ; i<jugadores ; i++ )
- {
- System.out.println( nombres[orden[i]] );
- if( (i+1)%grupos==0 ) System.out.println( "---" );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement