界说一个类People,成员变量有姓名,出生日期,性别,身高,体重等,成员体例有计较春秋,并建树该类的对象.
! z8 _6 V+ W0 H$ bimport java.util.Scanner;
9 Z& ^. E0 y* ~' W5 \. }& h5 P2 W
public class People
7 g: a/ {* `5 q2 u. M{
9 w9 y. `& y, U2 Q5 o1 y private int[] age;
2 f; N1 l' Y, J- t! b private double[] height;
: i1 F* s& Q0 J. S# C private double[] weight; , p( s0 A/ i, k/ \ @9 U
private String[] sex;
) J- w5 ~: k( c9 m private Date[] birthday;
' x' `# Q4 Z" w
& ~# u, {& l. ^$ A; m8 }, S4 l6 O, } public People (int n)
9 L8 u$ n5 r9 ]& j {
9 e6 h' s* v, c3 |* _4 x this.age = new int[n];
% `0 ]4 f: Z' c( Y this.height = new double[n]; + @- N) `# _& j* R& C; b
this.weight = new double[n]; , ^1 L8 K' A% |* [( Q
this.sex = new String[n]; , u! E/ w. c+ I
this.birthday = new Date[n];
3 x6 [2 I. p1 M8 c4 w2 a9 r; H# O6 w4 H* p/ ^. r
Scanner in = new Scanner(System.in);
: |! @" x1 Z2 F- V6 y" n for (int i = 0; i< n; i++)
2 u/ j' i" ], `5 ?3 g- ~8 C% Z { ' Q1 K) f) i1 Y8 D# N1 y2 N0 x5 q
System.out.println("Please input the age, height, weight, sex,and birthday");
0 n( v, ]* {9 e( X8 v$ d0 X age[n] = in.nextInt(); + _. w: L8 s/ L$ U
height [n] = in.nextDouble(); 4 W5 r8 r5 t/ n) [
weight [n] = in.nextDouble(); ) i+ \& Q* f) f3 {4 p
sex[n] = in.next(); 2 \5 `. {$ v) w8 `
birthday[n] = new Date(in.nextInt(),in.nextInt(),in.nextInt());
/ ^5 |' ~' P+ Z. } } + h8 ]; C. D. R7 c. k c
}
# [; [' s) G) U( q1 g8 ?
2 H" {: z6 u* C} |