为了账号安全,请及时绑定邮箱和手机立即绑定

为什么运行结果一直是8个零?求解!

为什么运行结果一直是8个零?求解!

hyl_666 2016-11-01 20:43:03
import java.util.Arrays;public class HelloWorld {    public static void main(String[] args) {                 // 创建对象,对象名为hello     HelloWorld hello = new HelloWorld();                // 调用方法并将返回值保存在变量中  int[] nums = hello.getArray(8);                // 将数组转换为字符串并输出  System.out.println(Arrays.toString(nums));  } /*  * 功能:创建指定长度的int型数组,并生成100以内随机数为数组中的每个元素赋值  * 定义一个带参带返回值的方法,通过参数传入数组的长度,返回赋值后的数组  */ public int[] getArray(int length) {        // 定义指定长度的整型数组  int[] nums = new int[length];                // 循环遍历数组赋值  for (   int i:nums  ) {               // 产生一个100以内的随机数,并赋值给数组的每个成员          num[i]=(int) (Math.random()*100);          }  return nums; // 返回赋值后的数组 }} 
查看完整描述

1 回答

已采纳
?
kofzxaaa

TA贡献66条经验 获得超26个赞

num[i]=(int) (Math.random()*100)中的num少打s了吧。

查看完整回答
反对 回复 2016-11-01
  • hyl_666
    hyl_666
    谢谢你,我加了s之后,结果还是8个零。
  • 1 回答
  • 0 关注
  • 1166 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信