zoukankan      html  css  js  c++  java
  • Arraylist Student

    1.student java

    package ArrayList;
    
    public class Student {
        private String name;
        private int age;
        private String sex;
    
        public Student() {
        }
    
        public Student(String name, int age, String sex) {
            this.name = name;
            this.age = age;
            this.sex = sex;
        }
    
        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;
        }
    
        public String getSex() {
            return sex;
        }
    
        public void setSex(String sex) {
            this.sex = sex;
        }
    }

    2.Student_demo

    package ArrayList;
    import java.util.ArrayList;
    public class student_demo {
        public static void main(String[] args) {
            Student one = new Student("Alex", 18, "male");
            Student two = new Student("Hull", 20, "male");
            Student three = new Student("Linda", 21, "female");
            Student four = new Student("Miranda", 18, "female");
            ArrayList<Student> list = new ArrayList<>(10);
            list.add(one);
            list.add(two);
            list.add(three);
            list.add(four);
            for(int i=0;i<list.size();i++){
                Student stu=list.get(i);
                System.out.println("student: "+stu.getName()+" age: "+stu.getAge()+" sex: "+stu.getSex());
            }
    
    
        }
    }

    ret://

    student: Alex age: 18 sex: male
    student: Hull age: 20 sex: male
    student: Linda age: 21 sex: female
    student: Miranda age: 18 sex: female

  • 相关阅读:
    c++笔记
    python笔记
    《c++不在难学--随老鸟快速通关》
    hexo
    hexo搭建
    《趣学算法》,陈小玉
    从机器学习谈起
    成不了AI高手?因为你根本不懂数据!听听这位老教授多年心血练就的最实用统计学
    PyTorch还是TensorFlow?这有一份新手指南
    win10下机器学习TensorFlow搭建
  • 原文地址:https://www.cnblogs.com/resort-033/p/12996372.html
Copyright © 2011-2022 走看看