Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.util.HashMap;
- import java.util.Scanner;
- import java.util.concurrent.ThreadLocalRandom;
- /**
- * Created by Sergi.
- * UPV 2016
- */
- public class probabilidad {
- public static void main(String[] args) throws FileNotFoundException{
- HashMap<Integer, Integer> alumnos = new HashMap<>();
- int repeticiones = 1000;
- int totalAlumnos = 20;
- for (int i = 1; i <= totalAlumnos; i++) {
- alumnos.put(i, 0);
- }
- for (int r = 1; r <= repeticiones; r++) {
- int random = ThreadLocalRandom.current().nextInt(1, totalAlumnos + 1);
- int value = alumnos.get(random);
- alumnos.put(random, value + 1);
- }
- Scanner sc = new Scanner(new File("alumnos.txt"));
- for (Integer name: alumnos.keySet()){
- String key = name.toString();
- int value = alumnos.get(name);
- float total = (float)value/repeticiones*100;
- System.out.printf("%2s %-32s %s \t %2.02f\n",key, sc.nextLine(), value, total);
- }
- sc.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement