美文网首页Java项目实战
java代码实现掷骰子

java代码实现掷骰子

作者: 大鱼鱼 | 来源:发表于2020-05-05 17:19 被阅读0次
    package javatext;
    
    public class 骰子 {
        public static void main (String[] args) {
            double d = Math.random();//生成[0,1)的随机数
            int a = (int)(Math.random()*6) + 1;//因为骰子的点数是[1,6],所以要加1,将doubl类型的数据强制转换为int类型数据。
            int b = (int)(Math.random()*6) + 1;
            int c = (int)(Math.random()*6) + 1;
            int count = a + b + c;
            if(count > 15) {
                System.out.println("今天手气不错");
            }
            if(count>=10&&count>=15) {
                System.out.println("运气一般");
            }
            if(count<=10) {
                System.out.println("今天手气不怎么样");
            }
            System.out.println("得了"+ count +"分");
        }
    
    }
    

    相关文章

      网友评论

        本文标题:java代码实现掷骰子

        本文链接:https://www.haomeiwen.com/subject/xztvghtx.html