package an.itcast_work;
import java.util.Scanner;
public class TestDemo3 {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
StringBuffer [] sbb=new StringBuffer[5];
Student st=new Student();
st.setName(sc.next());
st.setAge(sc.nextInt());
sbb[1].append(st.getName()).append(" ").append(st.getAge());
// Exception in thread "main" java.lang.NullPointerException
// at an.itcast_work.TestDemo3.main(TestDemo3.java:13)
System.out.println("***************");
Student st1=new Student();
st1.setName(sc.next());
st1.setAge(sc.nextInt());
sbb[1].append(st1.getName()).append(" ").append(st1.getAge());
System.out.println("***************");
Student st2=new Student();
st2.setName(sc.next());
st2.setAge(sc.nextInt());
sbb[2].append(st2.getName()).append(" ").append(st2.getAge());
System.out.println("***************");
Student st3=new Student();
st3.setName(sc.next());
st3.setAge(sc.nextInt());
sbb[3].append(st3.getName()).append(" ").append(st3.getAge());
System.out.println("***************");
Student st4=new Student();
st4.setName(sc.next());
st4.setAge(sc.nextInt());
sbb[4].append(st4.getName()).append(" ").append(st4.getAge());
System.out.println("***************");
for (int i = 0; i <sbb.length; i++) {
System.out.println(sbb[i].toString());
}
}
}
|
|