java - 在控制台中显示百分比(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");
}
解决方案
推荐阅读
- javascript - 当可见数据点全为零时,您可以隐藏 amCharts 图表中的图形吗?
- c# - 我有一个使用 c# 创建的 Azure Web 函数。并出现函数应用超时和主机关闭 4 分钟的间歇性问题
- python - 匹配数据名中具有相同位数的两列中的值
- python - 在匹配中将数组的值加倍 - Python
- arm - 在 macOS Intel 上生成和运行 ARMv8 SVE 二进制文件
- r - 结合5个ggplots
- discord - 当我添加新功能时,我的 disocrd 机器人崩溃了
- auc - 计算成对 AUC 曲线的协方差
- python - 向 pygame draw 方法添加表面位置参数的正确方法是什么?
- python - 为什么我得到 AttributeError:'NoneType' 对象没有属性 'label_map'