import java.util.*; class Student{ String name; String phone; public Student(String name,String phone){ this.name = name; this.phone = phone; } public String toString(){ return "姓名"+":"+name+" "+"电话"+":"+phone; } } public class Txl{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("请输入指令"); String x = sc.next(); Student st1 = new Student("i","1"); Student st2 = new Student("o","2"); List <Student>list = new ArrayList<Student>(); list.add(st1); list.add(st2); switch(x){ case "output": for(int i =0;i<list.size();i++) System.out.println(list.get(i)); break; } } }
答案来源网络,,供您参考
分享数据库前沿,解构实战干货,推动数据库技术变革