6-8次PTA题目集总结

6-8PTA题目集总结

前言

6次题目集

知识点:对象和类的创建和应用,字符串的创建和应用。

总共有1题,难度偏低,比较基础。

7次题目集

知识点:HashMap的创建和使用,多态,对象和类的创建和应用,字符串的创建和应用

总共有4题,难度中等。

8次题目集

知识点:ArrayList的创建和使用,接口的创建和使用,栈的概念,排序,对象和类的创建和应用,字符串的创建和应用,toString()方法的使用,equals的使用

总共有5题,难度偏高,题目较冷门。

正文

6次题目集

这次题目集虽然只有一题,但是写这题并不轻松,较繁琐,也让我有了一些进步。

7-1 课程成绩统计程序-1

这题总体来说并不难,只是很繁琐,但我在String的使用上出了问题,浪费了一些时间,导致一些测试点过不了。

写这题要注意区分输入的字符串,捕捉错误,不然会出错。

注意:成绩平均分只取整数部分,小数部分丢弃

import java.util.*;

public class Main {

/*java 必修 考试

20201103 张三 java 20 40

end*/

public static void main(String[] args) {

// TODO Auto-generated method stub

Scanner in=new Scanner(System.in);

String n;

String[] a;

n=in.nextLine();

Input handle=new Input();

 

while(!n.equals("end"))

{

 

try{

handle.choose(n);//解析用户输入的每一行数据

String[] z=n.split(" ");

}

 

catch(Exception ex) {System.out.println(" has no grades yet");}

n=in.nextLine();

}

handle.show();

//System.out.println("i end");

}

/* public int compareTo(Course o) {

        Comparator<Object> compare = Collator.getInstance(java.util.Locale.CHINA);

        return compare.compare(name,o.getName());

    }*/

}

class Input{

InputMatching[] s;

String xx;

String stuNumMatching;//8个0-9的数字

    String stuNumclass;//8个0-9的数字

    String stuNameMatching;//1到10个非空格(TAB)字符

    String score1;

    String score2;

    String score3;

    String courseNameMatching ;//1到10个非空格(TAB)字符

    String courseTypeMatching;

    String checkcourseTypeMatching;

public void  choose(String n)

{

String[] a=n.split(" ");

 

//for(int i=0;i<a.length;i++) {System.out.println(a[i]+i);}

if(a.length>=4) {

st(a);

}

 

else {

 

 

//xx=a[0];

//System.out.println(xx);

 

courseNameMatching=a[0];///?????????????????????/

//System.out.println(a[0]);

 

 

//System.out.println(stuNumclass);

courseTypeMatching=a[1];

checkcourseTypeMatching=a[2];

 

}

}

public void st(String[] a)

{

stuNumMatching=a[0];

stuNumclass=a[0].substring(0,6);

stuNameMatching=a[1];

if(a.length>4)

{

score1=a[3];

score2=a[4];

int s1,s2,s3;

s1=Integer.parseInt(score1);

s2=Integer.parseInt(score2);

s3=(int)(s1*0.3+s2*0.7);

score3=""+s3;

}

else {score2=score3=a[3]=a[3];

score1="";}

}

public void show()

{

System.out.println(stuNumMatching + " " + stuNameMatching + " " + score3);

if(score1.equals(""))System.out.println(courseNameMatching + " " + score2+" " + score3);

else System.out.println(courseNameMatching + " " + score1 + " " + score2+" " + score3);

System.out.println(stuNumclass + " " + score3);

}

}

 

class InputMatching {

 

    static String stuNumMatching;//8个0-9的数字

    static String stuNumclass = "[0-9]{8}";//8个0-9的数字

    static String stuNameMatching;//1到10个非空格(TAB)字符

    static String score1 = "([1-9]?[0-9]|100)";

    static String score2 = "([1-9]?[0-9]|100)";

    static String score3 = "([1-9]?[0-9]|100)";

    static String courseNameMatching ;//1到10个非空格(TAB)字符

    static String courseTypeMatching = "(选修|必修)";

    static String checkcourseTypeMatching = "(考试|考察)";

    //cousrInput用于定义课程信息模式(正则表达式)

    static String courseInput = courseNameMatching + " " + courseTypeMatching + " " + checkcourseTypeMatching;

    //scoreInput用于定义成绩信息模式(正则表达式)

    static String scoreInput = stuNumMatching + " " + stuNameMatching + " " + courseNameMatching + " " +

            score3 + "(scoreMatching)?";

    public static int matchingInput(String s) {

        if (matchingCourse(s)) {

            return 1;

        }

        if (matchingScore(s)) {

            return 2;

        }

        return 0;

    }

 

    private static boolean matchingCourse(String s) {

        return s.matches(courseInput);

    }

 

    private static boolean matchingScore(String s) {

        //System.out.println(match);

        return s.matches(scoreInput);

    }

}

 

7次题目集

这次题目集开始出现冷门的知识,但不难,完全可以自学。

7-1 容器-HashMap-检索

HashMapArrayList相似,但HashMap可以用对应的“钥匙”来得到储存的数据,实现了检索功能。

输入多个学生的成绩信息,包括:学号、姓名、成绩。

学号是每个学生的唯一识别号,互不相同。

姓名可能会存在重复。

使用HashMap存储学生信息,并实现根据学号的检索功能

import java.util.*;

public class Main {

public static void main(String[] args) {

// TODO Auto-generated method stub

Scanner in=new Scanner(System.in);

HashMap<String,String> h=new HashMap<String,String>();

String n=in.nextLine();

String k;

while(!n.equals("end"))

{

String [] n1=n.split(" ");

h.put(n1[0],n);

n=in.nextLine();

}

k=in.nextLine();

if(h.get(k)==null)System.out.println("The student "+k+" does not exist");

else System.out.println(h.get(k));

}

}

 

 

7-2 容器-HashMap-排序

这题需要对学生的学号排序,我是用排序法处理HashMap内的数据,但我现在认为可以使用Comparable接口进行排序,应该会更简便。

输入多个学生的成绩信息,包括:学号、姓名、成绩。

学号是每个学生的唯一识别号,互不相同。

姓名可能会存在重复。

要求:使用HashMap存储学生信息。//与上一题不同

 

import java.util.HashMap;

import java.util.Scanner;

public class Main {

public static void main(String[] args) {

// TODO Auto-generated method stub

Scanner in=new Scanner(System.in);

HashMap<Integer,String> h=new HashMap<Integer,String>();

String n=in.nextLine();

int n2,i=0,j,kn=0;

int[] k=new int[10];

while(!n.equals("end"))

{

String [] n1=n.split(" ");

n2=Integer.parseInt(n1[0]);

h.put(n2,n);

k[kn]=n2;

kn++;

n=in.nextLine();

}

for(i=0;i<kn;i++)

for(j=0;j<kn-1;j++)

{

if(k[j]<k[j+1]) {

n2=k[j];

k[j]=k[j+1];

k[j+1]=n2;

}

}

for(i=0;i<kn;i++)

{

System.out.println(h.get(k[i]));

}

}

}

 

7-3 课程成绩统计程序-2

这题只需在第一次的基础上改进一些即可,难度不算太大。

课程成绩统计程序-2在第一次的基础上增加了实验课

import java.util.*;

public class Main {

public static void main(String[] args) {

// TODO Auto-generated method stub

Scanner in=new Scanner(System.in);

String n;

String[] a;

n=in.nextLine();

Input handle=new Input();

while(!n.equals("end"))

{

try{

handle.choose(n);//解析用户输入的每一行数据

String[] z=n.split(" ");

}

catch(Exception ex) {System.out.println(" has no grades yet");}

n=in.nextLine();

}

handle.show();

//System.out.println("i end");

}

/* public int compareTo(Course o) {

        Comparator<Object> compare = Collator.getInstance(java.util.Locale.CHINA);

        return compare.compare(name,o.getName());

    }*/

}

class Input{

InputMatching[] s;

String xx;

String stuNumMatching;//8个0-9的数字

    String stuNumclass;//8个0-9的数字

    String stuNameMatching;//1到10个非空格(TAB)字符

    String score1;

    String score2;

    String score3;

    String courseNameMatching ;//1到10个非空格(TAB)字符

    String courseTypeMatching;

    String checkcourseTypeMatching;

public void  choose(String n)

{

String[] a=n.split(" ");

if(a.length>=4) {

st(a);

}

 

else {

courseNameMatching=a[0];

courseTypeMatching=a[1];

checkcourseTypeMatching=a[2];

 

}

}

public void st(String[] a)

{

stuNumMatching=a[0];

stuNumclass=a[0].substring(0,6);

stuNameMatching=a[1];

if(a.length>4)

{

score1=a[3];

score2=a[4];

int s1,s2,s3;

s1=Integer.parseInt(score1);

s2=Integer.parseInt(score2);

s3=(int)(s1*0.3+s2*0.7);

score3=""+s3;

}

else {score2=score3=a[3]=a[3];

score1="";}

}

public void show()

{

System.out.println(stuNumMatching + " " + stuNameMatching + " " + score3);

if(score1.equals(""))System.out.println(courseNameMatching + " " + score2+" " + score3);

else System.out.println(courseNameMatching + " " + score1 + " " + score2+" " + score3);

System.out.println(stuNumclass + " " + score3);

       

}

}

 

class InputMatching {

 

    static String stuNumMatching;//8个0-9的数字

    static String stuNumclass = "[0-9]{8}";//8个0-9的数字

    static String stuNameMatching;//1到10个非空格(TAB)字符

    static String score1 = "([1-9]?[0-9]|100)";

    static String score2 = "([1-9]?[0-9]|100)";

    static String score3 = "([1-9]?[0-9]|100)";

    static String courseNameMatching ;//1到10个非空格(TAB)字符

    static String courseTypeMatching = "(选修|必修)";

    static String checkcourseTypeMatching = "(考试|考察)";

    //cousrInput用于定义课程信息模式(正则表达式)

    static String courseInput = courseNameMatching + " " + courseTypeMatching + " " + checkcourseTypeMatching;

    //scoreInput用于定义成绩信息模式(正则表达式)

    static String scoreInput = stuNumMatching + " " + stuNameMatching + " " + courseNameMatching + " " +

            score3 + "(scoreMatching)?";

    public static int matchingInput(String s) {

        if (matchingCourse(s)) {

            return 1;

        }

        if (matchingScore(s)) {

            return 2;

        }

        return 0;

    }

 

    private static boolean matchingCourse(String s) {

        return s.matches(courseInput);

    }

 

    private static boolean matchingScore(String s) {

        //System.out.println(match);

        return s.matches(scoreInput);

    }

}

 

 

7-4 动物发声模拟器(多态)

这是一道典型的面向对象程序设计题,虽然可以直接面向过程设计,但我还是选择了面向对象设计,这题让我对面向对象程序设计有了全新的了解。

设计一个动物发生模拟器,用于模拟不同动物的叫声。比如狮吼、虎啸、狗旺旺、猫喵喵……。

定义抽象类Animal,包含两个抽象方法:获取动物类别getAnimalClass()、动物叫shout();

然后基于抽象类Animal定义狗类Dog、猫类Cat和山羊Goat,用getAnimalClass()方法返回不同的动物类别(比如猫,狗,山羊),用shout()方法分别输出不同的叫声(比如喵喵、汪汪、咩咩)。

最后编写AnimalShoutTest类测试,输出:

猫的叫声:喵喵

狗的叫声:汪汪

山羊的叫声:咩咩

其中,在AnimalShoutTestMain类中,用speak(Animal animal){}方法输出动物animal的叫声,在main()方法中调用speak()方法,分别输出猫、狗和山羊对象的叫声。

 

//动物发生模拟器.  请在下面的【】处添加代码。

public class Main {

    public static void main(String[] args) {        

         Cat cat = new Cat();

         Dog dog = new Dog();        

        Goat goat = new Goat();

         speak(cat);

         speak(dog);

         speak(goat);

    }

public static void speak(Animal a)

{

a.shout();

}

}

//定义抽象类Animal

abstract class Animal{

public abstract String getAnimalClass();

public abstract void shout();

}

//基于Animal类,定义猫类Cat,并重写两个抽象方法

 class Cat extends Animal{

public String getAnimalClass()

{

return "猫";

}

@Override

public void shout() {

// TODO Auto-generated method stub

System.out.println("猫的叫声:喵喵");

}

}

//基于Animal类,定义狗类Dog,并重写两个抽象方法

 class Dog extends Animal{

 public String getAnimalClass()

{

 return "狗";

}

 

@Override

public void shout() {

// TODO Auto-generated method stub

System.out.println("狗的叫声:汪汪");

}

}

//基于Animal类,定义山羊类Goat,并重写两个抽象方法

 class Goat extends Animal{

 public String getAnimalClass()

{

 return "山羊";

}

 

@Override

public void shout() {

// TODO Auto-generated method stub

System.out.println("山羊的叫声:咩咩");

}

}

 

 

 

8次题目集

这次题目集也出现冷门的知识,较难,需要上网查资料和分析实例来学习。

7-1 容器-ArrayList-排序

这题用ArrayList储存数据并排序,我使用了sort()函数排序,更方便。

输入多个学生的成绩信息,包括:学号、姓名、数学成绩、物理成绩。

学号是每个学生的唯一识别号,互不相同。

姓名可能会存在重复。

要求:使用ArrayList存储学生信息。

 

import java.util.*;

public class Main {

public static void main(String[] args) {

// TODO Auto-generated method stub

Scanner in=new Scanner(System.in);

int i;

ArrayList<String> a = new ArrayList<String>();

String n;

n=in.nextLine();

while(!n.equals("end"))

{

String [] n1=n.split(" ");

String n2=Integer.toString(Integer.parseInt(n1[3])+Integer.parseInt(n1[2]));

a.add(n1[0]+" "+n1[1]+" "+n2);

n=in.nextLine();

}

a.sort(null);

for(i=a.size()-1;i>=0;i--)

System.out.println(a.get(i));

}

}

 

 

7-2 课程成绩统计程序-3

这题相较第二次繁琐了许多,我写的较差。

课程成绩统计程序-3在第二次的基础上修改了计算总成绩的方式,

计算单个成绩时,分项成绩乘以权重后要保留小数位,计算总成绩时,累加所有分项成绩的权重分以后,再去掉小数位。

学生总成绩/整个班/课程平均分的计算方法为累加所有符合条件的单个成绩,最后除以总数。

6)如果解析实验课程信息时,输入的分项成绩数量值和分项成绩权重的个数不匹配,输出:课程名称+" : number of scores does not match"

7)如果解析考试课、实验课时,分项成绩权重值的总和不等于1,输出:课程名称+" : weight value error"

import java.util.*;

public class Main {

public static void main(String[] args) {

// TODO Auto-generated method stub

Scanner in=new Scanner(System.in);

String n;

String[] a;

n=in.nextLine();

Input handle=new Input();

while(!n.equals("end"))

{

try{

handle.choose(n);//解析用户输入的每一行数据

String[] z=n.split(" ");

}

catch(Exception ex) {System.out.println(" has no grades yet");}

n=in.nextLine();

}

handle.show();

//System.out.println("i end");

}

/* public int compareTo(Course o) {

        Comparator<Object> compare = Collator.getInstance(java.util.Locale.CHINA);

        return compare.compare(name,o.getName());

    }*/

}

class Input{

InputMatching[] s;

String xx;

String stuNumMatching;//8个0-9的数字

    String stuNumclass;//8个0-9的数字

    String stuNameMatching;//1到10个非空格(TAB)字符

    String score1;

    String score2;

    String score3;

    String courseNameMatching ;//1到10个非空格(TAB)字符

    String courseTypeMatching;

    String checkcourseTypeMatching;

public void  choose(String n)

{

String[] a=n.split(" ");

 

//for(int i=0;i<a.length;i++) {System.out.println(a[i]+i);}

if(a.length>=4) {

st(a);

}

else {

courseNameMatching=a[0];

courseTypeMatching=a[1];

checkcourseTypeMatching=a[2];

}

}

public void st(String[] a)

{

stuNumMatching=a[0];

stuNumclass=a[0].substring(0,6);

stuNameMatching=a[1];

if(a.length>4)

{

score1=a[3];

score2=a[4];

int s1,s2,s3;

s1=Integer.parseInt(score1);

s2=Integer.parseInt(score2);

s3=(int)(s1*0.3+s2*0.7);

score3=""+s3;

}

else {score2=score3=a[3]=a[3];

score1="";}

}

public void show()

{

System.out.println(stuNumMatching + " " + stuNameMatching + " " + score3);

if(score1.equals(""))System.out.println(courseNameMatching + " " + score2+" " + score3);

else System.out.println(courseNameMatching + " " + score1 + " " + score2+" " + score3);

System.out.println(stuNumclass + " " + score3);

       

}

}

 

class InputMatching {

 

    static String stuNumMatching;//8个0-9的数字

    static String stuNumclass = "[0-9]{8}";//8个0-9的数字

    static String stuNameMatching;//1到10个非空格(TAB)字符

    static String score1 = "([1-9]?[0-9]|100)";

    static String score2 = "([1-9]?[0-9]|100)";

    static String score3 = "([1-9]?[0-9]|100)";

    static String courseNameMatching ;//1到10个非空格(TAB)字符

    static String courseTypeMatching = "(选修|必修)";

    static String checkcourseTypeMatching = "(考试|考察)";

    //cousrInput用于定义课程信息模式(正则表达式)

    static String courseInput = courseNameMatching + " " + courseTypeMatching + " " + checkcourseTypeMatching;

    //scoreInput用于定义成绩信息模式(正则表达式)

    static String scoreInput = stuNumMatching + " " + stuNameMatching + " " + courseNameMatching + " " +

            score3 + "(scoreMatching)?";

    public static int matchingInput(String s) {

        if (matchingCourse(s)) {

            return 1;

        }

        if (matchingScore(s)) {

            return 2;

        }

        return 0;

    }

 

    private static boolean matchingCourse(String s) {

        return s.matches(courseInput);

    }

 

    private static boolean matchingScore(String s) {

        //System.out.println(match);

        return s.matches(scoreInput);

    }

}

 

 

7-3 jmu-Java-02基本语法-03-身份证排序

这题不难,较繁琐,使用了ToString()函数和contains()函数。注意输入的不是sort1或sort2,则输出exit并退出。

  1. 输入n,然后连续输入n个身份证号。
  2. 然后根据输入的是sort1还是sort2,执行不同的功能。输入的不是sort1或sort2,则输出exit并退出。
  3. 输入sort1,将每个身份证的年月日抽取出来,按-月-日格式组装,然后对组装后的-月-日升序输出。
  4. 输入sort2,将所有身份证按照里面的年月日升序输出。

 

import java.util.*;

public class Main {

public static void main(String[] args) {

Scanner in = new Scanner(System.in);

int n = in.nextInt(),j=0;

in.nextLine();

String a1[] = new String[n], a2[] = new String[n];

for (int i = 0; i < n; i++) {

a1[i] = in.nextLine();

}

String b = in.nextLine();

for ( ;b.equals("sort1") || b.equals("sort2");) {

if (b.equals("sort1")) {

for (j = 0; j < n; j++)

a2[j] = a1[j].substring(6, 10) + "-" + a1[j].substring(10, 12) + "-" + a1[j].substring(12, 14);

Arrays.sort(a2);

for ( j = 0; j < n; j++)

System.out.println(a2[j].toString());

}

else if (b.equals("sort2")) {

for ( j = 0; j < n; j++) {

a2[j] = a1[j].substring(6, 14);

}

Arrays.sort(a2);

for ( j = 0; j < n; j++)

for (int k = 0; k < n; k++)

if (a1[k].contains(a2[j]))

System.out.println(a1[k].toString());

}

b = in.nextLine();

}

 System.out.println("exit");

}

}

 

 

7-4 jmu-Java-04面向对象进阶-03-接口-自定义接口ArrayIntegerStack

这题增加了接口和栈,我上网查询解决了问题,学会了while(x-- > 0)的作用

定义IntegerStack接口,用于声明一个存放Integer元素的栈的常见方法:

定义IntegerStack的实现类ArrayIntegerStack,内部使用数组实现。创建时,可指定内部数组大小。

main方法说明

  1. 输入n,建立可包含n个元素的ArrayIntegerStack对象
  2. 输入m个值,均入栈。每次入栈均打印入栈返回结果。
  3. 输出栈顶元素,输出是否为空,输出size
  4. 使用Arrays.toString()输出内部数组中的值。
  5. 输入x,然后出栈x次,每次出栈均打印。
  6. 输出栈顶元素,输出是否为空,输出size
  7. 使用Arrays.toString()输出内部数组中的值。

 

import java.util.*;

interface IntegerStack {

    public Integer push(Integer item); //如果item为null,则不入栈直接返回null。如果栈满,也返回null。如果插入成功,返回item

    public Integer pop();   //出栈,如果为空,则返回null。出栈时只移动栈顶指针,相应位置不置为null

    public Integer peek();  //获得栈顶元素,如果为空,则返回null

    public boolean empty(); //如果为空返回true

    public int size();      //返回栈中元素个数

}

class ArrayIntegerStack implements IntegerStack{

    private Integer[] arr;

    private int top = 0;

    public ArrayIntegerStack(int n){

        arr = new Integer[n];

        Arrays.fill(arr, null);

    }

    public ArrayIntegerStack(){}

    public String toString() {

        return Arrays.toString(arr);

    }

    public Integer push(Integer item) {

        if (item == null || arr.length == top){

            return null;

        }

        arr[top++] = item;

        return item;

    }

    public Integer pop() {

        if (top == 0){

            return null;

        }

        return arr[--top];

    }

    public Integer peek() {

        if (top == 0){

            return null;

        }

        return arr[top - 1];

    }

    public boolean empty() {

        return top == 0;

    }

    public int size() {

        return top;

    }

}

public class Main {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);

        int n = in.nextInt();

        ArrayIntegerStack a = new ArrayIntegerStack(n);

        int m = in.nextInt();

        while(m-- > 0){

            int item = in.nextInt();

            System.out.println(a.push(item));

        }

        System.out.println(a.peek() + "," + a.empty() + "," + a.size());

        System.out.println(a);

        int x = in.nextInt();

        while(x-- > 0){

            System.out.println(a.pop());

        }

        System.out.println(a.peek() + "," + a.empty() + "," + a.size());

        System.out.println(a);

    }

}

 

 

7-5 jmu-Java-03面向对象基础-05-覆盖

这题较繁琐,我使用ArrayList简化代码。

ava每个对象都继承自Object,都有equals、toString等方法。

现在需要定义PersonOverride类并覆盖其toString与equals方法。

1. 新建PersonOverride

a. 属性:String name、int age、boolean gender,所有的变量必须为私有(private)。

b. 有参构造方法,参数为name, age, gender

c. 无参构造方法,使用this(name, age,gender)调用有参构造方法。参数值分别为"default",1,true

d.toString()方法返回格式为:name-age-gender

e. equals方法需比较name、age、gender,这三者内容都相同,才返回true.

2. main方法

2.1 输入n1,使用无参构造方法创建n1个对象,放入数组persons1。

2.2 输入n2,然后指定name age gender。每创建一个对象都使用equals方法比较该对象是否已经在数组中存在,如果不存在,才将该对象放入数组persons2。

2.3 输出persons1数组中的所有对象

2.4 输出persons2数组中的所有对象

2.5 输出persons2中实际包含的对象的数量

2.5 使用System.out.println(Arrays.toString(PersonOverride.class.getConstructors()));输出PersonOverride的所有构造方法。

提示:使用ArrayList代替数组大幅复简化代码,请尝试重构你的代码。

 

import java.util.*;

class PersonOverride{

    private String name;

    private int age;

    private boolean gender;

    public String toString() {

        return name + "-" + age + "-" + gender;

    }

    public boolean equals(Object o){

        if (this == o){

            return true;

        }

        if(o == null)

        {

            return false;

        }

        if (this.getClass() != o.getClass()){

            return false;

        }

        PersonOverride p = (PersonOverride)o;

        boolean a1 = Objects.equals((this.name), p.name);

        boolean a2 = (this.age == p.age);

        boolean a3 = (this.gender == p.gender);

        if(a1 && a2 && a3){

            return true;

        }

        return false;

    }

    public PersonOverride(String _name, int _age, boolean _gender){

        name = _name;

        age = _age;

        gender = _gender;

    }

    public PersonOverride(){

        this("default",1,true);

    }

}

public class Main {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);

        int i,count = 0;

        int n1 = in.nextInt();

        PersonOverride[] person1 = new PersonOverride[n1];

        for (i = 0; i < n1; i++) {

            person1[i] = new PersonOverride();

        }

        int n2 = in.nextInt();

        in.nextLine();

        PersonOverride[] person2 = new PersonOverride[n2];

        for (i = 0; i < n2; i++) {

            String str = in.nextLine();

            String[] arr = str.split("\\s+");

            PersonOverride temp = new PersonOverride(arr[0],Integer.parseInt(arr[1]),Boolean.valueOf(arr[2]));

            boolean f = true;

            for (int j = 0; j < n2; j++) {

                if(temp.equals(person2[j])){

                    f = false;

                }

            }

            if(f){

                person2[i] = new PersonOverride(arr[0],Integer.parseInt(arr[1]),Boolean.valueOf(arr[2]));

            }

        }

        for ( i = 0; i < n1; i++) {

            System.out.println(person1[i]);

        }

        

        for (i = 0; i < n2; i++) {

            if(person2[i] == null){

                continue;

            }

            count++;

            System.out.println(person2[i]);

        }

        System.out.println(count);

        System.out.println(Arrays.toString(PersonOverride.class.getConstructors()));

    }

}

 

 总结

  在这三次题目集中,我掌握了java的一些冷门知识,复习了类和字符串的使用,写代码更加精简。另外,在栈方面,我认为我的掌握不够,需要进一步研究。学到这里,java的课程即将告一段落,我感觉我还有许多不足,我还有进步的空间,希望我能在以后的学习中更进一步。最后,我希望老师能增加课堂互动和实例讲解,对学生掌握知识点有帮助。

posted @ 2023-06-28 14:47  hanling  阅读(177)  评论(0)    收藏  举报