Exercises

1.掌握打印流以及Scanner类的常用方法,使用打印流和Scanner优化之前的FileInputStream与FileOutputStream操作。要求:在桌面上新建一个Test.txt,使用打印流向文件中输出如下:

Hello 123

Hello bit

然后使用Scanner类读取文件内容并输入到控制台。

import java.io.*;
import java.util.Scanner;

/**
 * 要求:在桌面上新建一个Test.txt,使用打印流向文件中输出如下:
 * Hello 123
 * Hello bit
 * 然后使用Scanner类读取文件内容并输入到控制台。
 */
public class DemoIO {
    public static void main(String[] args) throws FileNotFoundException {
        File file=new File("C:\\Users\\Lenovo\\Desktop\\Test.txt");
        if(!file.exists()){
            try {
                file.createNewFile();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        //定义PrintStream类,向文件中写数据
        PrintStream printStream=new PrintStream(new FileOutputStream(file));
        printStream.print("Hello ");
        printStream.println("123");
        printStream.print("Hello bit");
        printStream.close();//关闭流
        //使用Scanner类输入到控制台中
        Scanner scanner=new Scanner(new FileInputStream(file));
        scanner.useDelimiter("\r\n");//定义分隔模式
        while(scanner.hasNext()){
            System.out.println(scanner.next());
        }
    }
}

2.要求自定义Person类,其中三个属性name,age,school.age属性不作为序列化保存而其它两个属性使用序列化保存在本地文件Tester.txt文件中。使用序列化与反序列化的方式将自定义类序列化与反序列化操作。

import java.io.*;

/**
 * 要求自定义Person类,其中三个属性name,age,school.age属性不作为序列化保存而其它两个属性使用序列化保存在本地文件Tester.txt文件中。使用序列化与反序列化的方式将自定义类序列化与反序列化操作。
 */
class Person implements Serializable {
    private String name;
    private transient int age;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Person{" +
                "name='" + name + '\'' +
                ", age=" + age +
                ", school='" + school + '\'' +
                '}';
    }

    public String getSchool() {
        return school;
    }

    public void setSchool(String school) {
        this.school = school;
    }

    private String school;
}
public class DemoIO {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
//        C:\\Users\\Lenovo\\Desktop\\Test.txtC:\\Users\\Lenovo\\Desktop\\Test.txt
//        "C"+File.separator+"Users"+File.separator+"Lenovo"+File.separator+"Desktop"+File.separator+"Test.txt"
        File file=new File("C:\\Users\\Lenovo\\Desktop\\Test.txt");
        if(!file.exists()){
            file.createNewFile();
        }
        Person person=new Person();
        person.setName("张三");
        person.setAge(19);
        person.setSchool("陕科大");
       //对象序列化输出
//        ObjectOutputStream out=new ObjectOutputStream(new FileOutputStream(file));
//        out.writeObject(person);
//        out.close();
        //读取
        ObjectInputStream in=new ObjectInputStream(new FileInputStream(file));
        Person per= (Person) in.readObject();
        System.out.println(per);
        in.close();
    }
}

3.输入一个5位数,判断它是不是回文数。即12321是回文数,个位与万位相同,十位与千位相同。

import java.io.*;
import java.util.Scanner;

/**
 *输入一个5位数,判断它是不是回文数。即12321是回文数,个位与万位相同,十位与千位相同。
 */

public class DemoIO {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        while(sc.hasNext()){
//    方式一:
//            int k=sc.nextInt();
//            int[] arr=new int[5];
//            for(int i=0;i<5;i++){
//                arr[i]=k%10;
//                k/=10;
//            }
//
//            if(arr[0]==arr[4]&&arr[1]==arr[3]){
//                System.out.println("是回文数");
//            }else{
//                System.out.println("不是回文数");
//            }
//     不限制长度 适用于任何回文串
            String k=sc.next();
            char[] ch=k.toCharArray();
            int begin=0;
            int end=ch.length-1;
            while(begin<end){
                if(ch[begin++]!=ch[end--]){
                    System.out.println("不是回文数");
                    break;
                }
            }
            if(begin>=end) {
                System.out.println("是回文数");
            }
        }

    }
}

 

Focusing on high-dimensional applications, this 4th edition presents the tools and concepts used in multivariate data analysis in a style that is also accessible for non-mathematicians and practitioners. It surveys the basic principles and emphasizes both exploratory and inferential statistics; a new chapter on Variable Selection (Lasso, SCAD and Elastic Net) has also been added. All chapters include practical exercises that highlight applications in different multivariate data analysis fields: in quantitative financial studies, where the joint dynamics of assets are observed; in medicine, where recorded observations of subjects in different locations form the basis for reliable diagnoses and medication; and in quantitative marketing, where consumers’ preferences are collected in order to construct models of consumer behavior. All of these examples involve high to ultra-high dimensions and represent a number of major fields in big data analysis. The fourth edition of this book on Applied Multivariate Statistical Analysis offers the following new features: A new chapter on Variable Selection (Lasso, SCAD and Elastic Net) All exercises are supplemented by R and MATLAB code that can be found on www.quantlet.de. The practical exercises include solutions that can be found in Härdle, W. and Hlavka, Z., Multivariate Statistics: Exercises and Solutions. Springer Verlag, Heidelberg. Table of Contents Part I Descriptive Techniques Chapter 1 Comparison of Batches Part II Multivariate Random Variables Chapter 2 A Short Excursion into Matrix Algebra Chapter 3 Moving to Higher Dimensions Chapter 4 Multivariate Distributions Chapter 5 Theory of the Multinormal Chapter 6 Theory of Estimation Chapter 7 Hypothesis Testing Part III Multivariate Techniques Chapter 8 Regression Models Chapter 9 Variable Selection Chapter 10 Decomposition of Data Matrices by Factors Chapter 11 Principal Components Analysis Chapter 12 Factor Analysis Chapter 13 Cluster Analysis Chapter 14 Discri
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值