0

I have a problem with my code, it doesn't show the percentage correctly in the console. I tried a lot of thing, a little help would be much appreciate.

Thank you!

  public static void exercice1() {
  int egale = 0;
Random rand = new Random(); 
System.out.println("==== Lancer d'une pièce (10 fois) =====");
for (int i=1; i<=1000000; i++){
  int lancer = rand.nextInt(6)+1;
  int lancer2 = rand.nextInt(6)+1;
  int lancer3 = rand.nextInt(6)+1;
 if(lancer == lancer2 && lancer2 == lancer3 && lancer3 == lancer) {
     egale++;
    System.out.println("Les dés on été sembable "+egale+ " fois");
 }
     
     
}
double pourcentage = ((egale / 1000000) * 100);
DecimalFormat df = new DecimalFormat("#.##");
System.out.println("Les dés on été sembable "+Double.valueOf(df.format(pourcentage))+ "% du temps");

}

Pointy
  • 405,095
  • 59
  • 585
  • 614

0 Answers0