皮皮网

【淘宝客源码下载地址】【黑彩源码】【sklearn 源码下载】java免费源码分享源码_java源码分享平台

时间:2024-11-18 20:35:24 来源:代码源码反码

1.java源代码 求大神 明天就要上机

java免费源码分享源码_java源码分享平台

java源代码 求大神 明天就要上机

       package com.uisftec;

       import java.io.Serializable;

       public class TestScores implements Serializable {

        private double[] testScores;

        public TestScores(double[] testScores) {

        this.testScores = testScores;

        }

        public double getAverageScore() {

        double sum = 0.0d;

        for (int i = 0; i < testScores.length; i++) {

        sum += testScores[i];

        }

        return sum / testScores.length;

        }

       }

       package com.uisftec;

       public class InvalidTestScore {

        public InvalidTestScore(double[] testScores) {

        if (testScores == null) {

        throw new IllegalArgumentException("数组为空");

        }

        for (int i = 0; i < testScores.length; i++) {

        if (testScores[i] < 0 || testScores[i] > ) {

        throw new IllegalArgumentException("数组中包含的免费淘宝客源码下载地址test Score不在0~这个范围内");

        }

        }

        }

       }

       package com.uisftec;

       import java.io.DataOutputStream;

       import java.io.File;

       import java.io.FileInputStream;

       import java.io.FileNotFoundException;

       import java.io.FileOutputStream;

       import java.io.IOException;

       import java.io.ObjectInputStream;

       import java.io.ObjectOutput;

       import java.io.ObjectOutputStream;

       public class TestScoresSerialize {

        public static void main(String[] args) throws FileNotFoundException, IOException, ClassNotFoundException {

        // 创建5个对象

        TestScores testScores1 = new TestScores(new double[] { 1.0, 2.0 });

        TestScores testScores2 = new TestScores(new double[] { 5.0, 2.0 });

        TestScores testScores3 = new TestScores(new double[] { .0, .0 });

        TestScores testScores4 = new TestScores(new double[] { .0, .0 });

        TestScores testScores5 = new TestScores(new double[] { .0, .0 });

        // 创建数组

        TestScores[] testScores = new TestScores[] { testScores1, testScores2, testScores3, testScores4, testScores5 };

        // 写入到D盘testScores.dat

        ObjectOutput out = new ObjectOutputStream(new FileOutputStream("d:\\testscores.dat"));

        for (TestScores testScores6 : testScores) {

        out.writeObject(testScores6);

        }

        // D盘STOUT

        File file = new File("D:\\STDOUT");

        // 创建输出留

        DataOutputStream outputStream = new DataOutputStream(new FileOutputStream(file));

        // 创建读取d盘序列化对象

        ObjectInputStream in = new ObjectInputStream(new FileInputStream("d:\\testscores.dat"));

        // 打印平均分并写入到D盘STDOUT

        TestScores testScores8 = (TestScores) in.readObject();

        System.out.println(testScores8.getAverageScore());

        outputStream.writeDouble(testScores8.getAverageScore());

        TestScores testScores9 = (TestScores) in.readObject();

        outputStream.writeDouble(testScores9.getAverageScore());

        System.out.println(testScores9.getAverageScore());

        TestScores testScores = (TestScores) in.readObject();

        System.out.println(testScores.getAverageScore());

        outputStream.writeDouble(testScores.getAverageScore());

        TestScores testScores = (TestScores) in.readObject();

        System.out.println(testScores.getAverageScore());

        outputStream.writeDouble(testScores.getAverageScore());

        TestScores testScores = (TestScores) in.readObject();

        System.out.println(testScores.getAverageScore());

        outputStream.writeDouble(testScores.getAverageScore());

        // 关闭流

        out.close();

        in.close();

        outputStream.close();

        }

       }

推荐资讯
sksockserver 源码

sksockserver 源码

惠州鑫月广场离轻轨站源码_惠州鑫月广场在哪里

惠州鑫月广场离轻轨站源码_惠州鑫月广场在哪里

通达信多空线选股源码_通达信 多空线

通达信多空线选股源码_通达信 多空线

小明捡垃圾脚本源码编辑器

小明捡垃圾脚本源码编辑器

uc 源码

uc 源码

单片机做贪吃蛇的源码_单片机 贪吃蛇

单片机做贪吃蛇的源码_单片机 贪吃蛇

copyright © 2016 powered by 皮皮网   sitemap