java程序编译掷骰子游戏的思路

编写一个简单程序模拟掷骰子游戏,掷一次骰子可能得随机得到1、2、3、4、5、6中任意一个数,一个人可以掷两次,要求程序计算出两次的平均值。输出结果如下:

The first die comes up 3
The second die comes up 5
Your total roll is 8

public class Control {
public static void main(String[] args) {
double d = Math.random();// 这是一个生成随机数字的函数0-1
int f=(int)(1+d*6);
System.out.print("The first die comes up ");
System.out.println(f);
double s=Math.random();
int k=(int)(1+s*6);
System.out.print("The second die comes up ");
System.out.println(k);
int p=f+k;
System.out.print("Your total roll is ");
System.out.println(p);
}
}

public class Control {
public static void main(String[] args) {
double d = Math.random();
int f=(int)(1+d*6);
System.out.println("The first die comes up "+f);//掷骰子

double s=Math.random();
int k=(int)(1+s*6);
System.out.println("The second die comes up "+k);
int p=f+k;
System.out.println("Your total roll is "+p);
}
}

图片说明

package testcast;

public class NewRandom {
//初学者 见笑了
public static int random() {
return (int)(1+Math.random()*6);
}
public static void main(String[] args) {
int R1=random();
int R2=random();
int R3=R1+R2;
System.out.println("The first die comes up " +R1 );
System.out.println("The second die comes up " +R2);
System.out.println("Your total roll is " +R3);
}

}