Skip to content

Instantly share code, notes, and snippets.

@sandeeprsp
Last active November 27, 2016 11:46
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;
public class LogicalClass {
//results are saved in map
static Map<Integer,Integer> mappings=new TreeMap<Integer,Integer>();
static List<Integer> listNumbers1=new ArrayList<Integer>();
static List<Integer> listNumbers2=new ArrayList<Integer>();
public static void match(){
//taking input from users.
System.out.println("enter the number of players");
Scanner sc=new Scanner(System.in);
int players=sc.nextInt();
for(int i=0;i<players;i++){
listNumbers.add(i+1);
listNumbe.add(i+1);
}
// shuffle mehtod using to randomize the elements in list.
Collections.shuffle(listNumbers);
Collections.shuffle(listNumbe);
for(int i=0;i<players;i++){
mappings.put(listNumbers.get(i),listNumbe.get((players-1)-i));
}
for(Map.Entry<Integer,Integer> entry : mappings.entrySet()) {
System.out.println(entry.getKey()+"should be secret santa for "+entry.getValue());
}
sc.close();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment