Dice1.txt import java.math.*;import java.util.*;class Test1 { public static void main(String[] args) { Dice d = new Dice(); d.play(); System.out.println("骰子合计值是:" +d.sum); }}class Dice{ int decision=1; int value; static int su
import java.math.*; import java.util.*; class Test1 { public static void main(String[] args) { Dice d = new Dice(); d.play(); System.out.println("骰子合计值是:" +d.sum); } } class Dice{ int decision=1; int value; static int sum; int n; int begin; int num; public void play(){ @SuppressWarnings("resource") Scanner s = new Scanner(System.in); System.out.println("输入1,使用默认骰子设置(骰子数量:3, 骰子最小值:1 骰子面值个数:2),其他数值,使用自定义设置:"); decision = s.nextInt(); if(decision ==1){ n = 3; begin = 1; num = 2; } else{ System.out.println("请输入骰子数量:"); n = s.nextInt(); System.out.println("请输入骰子最小值:"); begin = s.nextInt(); System.out.println("请输入骰子面值个数:"); num = s.nextInt(); } for(int i =1;i<=n;i++){ value = (int)(Math.random()*10)%num+begin; System.out.println("骰子" + i + "的值是 :" +value); sum+=value; } } }