JAVA33. 掷骰子游戏
描述
开发一个掷骰子游戏,即每次运行程序时,产生一个[1,6]之间的随机整数(关于seed的问题可以参考题解)。输入描述
随机数种子输出描述
[1,6]之间的随机整数示例1
输入:
100
输出:
2
Java 解法, 执行用时: 29ms, 内存消耗: 10696KB, 提交时间: 2022-02-08
import java.util.Random; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNextInt()) { int seed = scanner.nextInt(); Random random = new Random(seed); //write your code here...... System.out.println(random.nextInt(6) + 1); } } }
Java 解法, 执行用时: 29ms, 内存消耗: 10724KB, 提交时间: 2022-02-10
import java.util.Random; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNextInt()) { int seed = scanner.nextInt(); Random random = new Random(seed); System.out.println(random.nextInt(6)+1); } } }
Java 解法, 执行用时: 29ms, 内存消耗: 10880KB, 提交时间: 2022-02-08
import java.util.Random; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNextInt()) { int seed = scanner.nextInt(); Random random = new Random(seed); //write your code here...... System.out.println(1+random.nextInt(6)); } } }
Java 解法, 执行用时: 30ms, 内存消耗: 10616KB, 提交时间: 2021-11-29
import java.util.Random; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNextInt()) { int seed = scanner.nextInt(); Random random = new Random(seed); //write your code here...... int num = random.nextInt(6)+1; System.out.println(num); } } }
Java 解法, 执行用时: 30ms, 内存消耗: 10660KB, 提交时间: 2021-10-29
import java.util.Random; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); while (scanner.hasNextInt()) { int seed = scanner.nextInt(); Random random = new Random(seed); System.out.println(random.nextInt(6) + 1); } } }