zoukankan      html  css  js  c++  java
  • 用对象型泛型和ArraysList写一个输入学员信息并展示

    题目:录入学员信息并保存,当录入学员的编号为0时结束,展示出学员信息

    //student类

    public class Student {   

           public int id;

           public String name;    

           public int age;   

           public Student() {

                 super();

           }

           public Student(int id, String name, int age) {

                 super();

                 this.id = id;   

                 this.name = name;  

                 this.age = age;  

    }

    //text

    public class Text {
          public static void main(String[] args) {
                System.out.println("*****录入学员信息,当录入学员的编号为0时结束*****");
                Scanner input = new Scanner(System.in);
                ArrayList<Student> arraylist = new ArrayList<Student>();
                //输入学员信息
                while(true){
                     Student student = new Student();
                     System.out.print("请输入学员学号:");
                     student.id = input.nextInt();
                     if(student.id==0){
                           System.out.println("结束录入!");
                           break;
                     }else{
                           System.out.print("请输入学员姓名:");
                           student.name = input.next();
                           System.out.print("请输入学员年龄:");
                           student.age = input.nextInt();
                           arraylist.add(student);
                     }
                 }
            
                 //输出学员信息
                 System.out.println("学员的信息如下:");
                 System.out.println("学号 姓名 年龄");
                 Iterator<Student> iterator = arraylist.iterator();
                 while(iterator.hasNext()){
                        Student a = iterator.next();
                        System.out.println(a.id+" "+a.name+" "+a.age);
                  }

    }

    运行结果:

  • 相关阅读:
    Java 开发必装的 IntelliJ IDEA 插件
    paoding-rose 之 maven配置
    jetty之maven配置
    paoding rose controller包及文件名命名规则
    PowerMock进行mock测试
    谈谈我的windows服务器运维管理
    谈谈RPC中的异步调用设计
    系统:WSL(win10的子系统Linux)
    信息安全攻防基础
    线性规划计算工具Lingo
  • 原文地址:https://www.cnblogs.com/wangxinqiang1995/p/5774609.html
Copyright © 2011-2022 走看看