《java实验考》由会员分享,可在线阅读,更多相关《java实验考(7页珍藏版)》请在金锄头文库上搜索。
1、1.(25 分) 产生一个 int 数组 a,长度为 100,并向其中随机填充三位的整数,然后再从该 100个随机数中任意抽取 10 形成一个 10 个数的数组 b,再将数组 b 输出。代码:/* 1.(25分)产生一个int数组 a,长度为100,并向其中随机填充三位的整数,* 然后再从该100个随机数中任意抽取 10形成一个10个数的数组 b,再将数组b输出。* version 1.0*/package wangshuai;/数组a,100import java.util.Random;public class RandomArray public static int getArray(
2、int length, int downLimit, int upLinit) int originalArr = new intlength;int result = new int10;Random r = new Random();for (int i = 0; i = 0 & arr0 = 0 & arri = 0 & resulti = 0 & resultj list = new ArrayList();Circle circle = null;Random r = new Random();for (int i = 0; i result) throws IOExceptionI
3、terator iter = null;Circle circle = null;File file = new File(src);if(!file.exists()file.createNewFile();FileOutputStream fos = new FileOutputStream(file);DataOutputStream dos = new DataOutputStream(fos);iter = result.iterator();while(iter.hasNext()circle = iter.next();dos.writeInt(circle.getCenterX();dos.writeInt(circle.getCenterY();dos.writeDouble(circle.getRadius();dos.writeDouble(circle.area();dos.close();fos.close();public static void main(String args) throws IOException / TODO Auto-generated method stubnew ExamTest02();