- import java.util.*;
- class Demo13
- {
- public static void main(String[] args)
- {
- //Scanner sc = new Scanner(System.in);
- Person[] arr = new Person[3];
-
- for(int i=0;i<arr.length;i++)
- {
- Scanner sc = new Scanner(System.in);//放在循环语句中
-
- System.out.println("输入姓名:");
- String n = sc.nextLine();
- System.out.println("输入姓别:");
- String s = sc.nextLine();
- System.out.println("输入年龄:");
- int a = sc.nextInt();
- arr[i] = new Person();
- arr[i].name = n;
- arr[i].sex = s;
- arr[i].age = a;
- }
- for(int i=0;i<arr.length;i++)
- {
- System.out.println(arr[i].name+" "+arr[i].sex+" "+arr[i].age);
- }
- }
- }
- class Person
- {
- String name;
- String sex;
- int age;
- }
复制代码 这样就可以了 |
|