.编写application,调用以下两个自定义两个方法:方法abc( )的参数为int类型,返回值为double型数组,功能为生成随机的double数组,数组元素值在10~20之间,数组元素个数从参数传入;方法printA()的参数double数组,功能为将参数数组在命令行分行打印输出。
小弟我按找你说的写了一个,可能没读明白你的意思,如果有什么不对,请指出: import java.math.*; import java.io.*; public class Test { public static void main(String[] args) { System.out.print("enter j:"); int j=MyInput.readInt(); double[] s; s=abc(j); printA(s); } static double[] abc(int i) { double[] s=new double[i]; for(int k=0;k<s.length;k++) {s[k]=(Math.random()*20); if(s[k]<10) s[k]=s[k]+10; } return s; } static void printA(double[] s) { for(int i=0;i<s.length;i++ ) System.out.println(s[i]); } }
class MyInput { static String readString() { BufferedReader br=new BufferedReader(new InputStreamReader(System.in),1); String string=" "; try { string=br.readLine(); } catch(IOException e) { System.out.println(e); } return string; } public static int readInt() { return Integer.parseInt(readString()); } }






2005-5-18 15:54 