far8357
发贴: 2
积分: 0
|
于 2006-04-22 08:35
nextInt 函数不是int型的吗,为什么下面这个类输出的都是小数形式的呀?
package com;
import java.util.*;
public class PrintTwoArray{ double[][] s=new double[2][3];//定义一个二维数组 Random rand=new Random();//定义随机对象 //给2维数组赋值 void getarray(int a,int b){ for(int i=0;i<s.length;i++){ for(int j=0;j<s[i].length;j++){ s[i][j]=rand.nextInt()*((a+b)/2);//用nextdouble()返回一个0~1之间的值 } } } //打印2维数组 void printarray(){ for(int n=0;n<s.length;n++){ for(int m=0;m<s[n].length;m++){ System.out.println(s[n][m]); } } }
public static void main(String[] args){ PrintTwoArray s2=new PrintTwoArray();//定义一个这个类的对象 s2.getarray(4,6);//使用getarray()方法给数组赋值 s2.printarray();//打印数组 } }
|