首页 > 解决方案 > 在控制台中显示百分比(JAVA)

问题描述

我的代码有问题,它没有在控制台中正确显示百分比。我尝试了很多东西,一点帮助将不胜感激。

谢谢!

  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");

}

标签: java

解决方案


推荐阅读