gpt4 book ai didi

java - 如何以更 "elegant"的方式重写这行代码?

转载 作者:行者123 更新时间:2023-12-01 06:51:12 24 4
gpt4 key购买 nike

所以我有这行代码,我正在尝试找到一种方法以更优雅的方式编写它们:

         int randomHints1 = hintsRandom.nextInt(1200-100) + 100;
int randomHints2 = hintsRandom.nextInt(1200-100) + 100;
int randomHints3 = hintsRandom.nextInt(1200-100) + 100;
int randomHints4 = hintsRandom.nextInt(1200-100) + 100;
int randomHints5 = hintsRandom.nextInt(1200-100) + 100;
int randomHints6 = hintsRandom.nextInt(1200-100) + 100;
int randomHints7 = hintsRandom.nextInt(1200-100) + 100;
int randomHints8 = hintsRandom.nextInt(1200-100) + 100;
int randomHints9 = hintsRandom.nextInt(1200-100) + 100;
int randomHints10 = hintsRandom.nextInt(1200-100) + 100;

我猜“for循环”方法就是答案,但我找不到解决这个问题的方法。非常感谢大家。

最佳答案

int[] randomHints = new int[10];
for(int i=0;i<randomHints.length;i++)
randomHints[i] = hintsRandom.nextInt(1100) + 100;

关于java - 如何以更 "elegant"的方式重写这行代码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27790289/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com