일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
Tags
- angular2
- 업캐스팅
- 형변환
- 자바
- 스프링
- 페이징
- 전체
- 가변인자
- 전자정부
- 25가지 효율적인 sql작성법
- 자바 야구게임
- 상속
- Validations
- 야구게임
- 전체텍스트
- IBatis procedure
- 이클립스
- 다형성
- 단축키
- 상속예제
- 로또
- while
- 다운캐스팅
- Random
- Full text
- full text indexing
- Login with OAuth Authentication
- 추상클래스
- jquery
Archives
- Today
- Total
nalaolla
오브젝트 예제 2 (배열활용) 본문
728x90
반응형
- package test.com;
- public class Test02Person {
- int height;
- int weight;
- String location;
- String[] friends;
- public Test02Person() {
- height = 187;
- weight = 80;
- location = "Guri";
- friends = new String[3];
- friends[0] = "AA";
- friends[1] = "BB";
- friends[2] = "CC";
- }
- public Test02Person(int height, int weight, String location) {
- this.height = height;
- this.weight = weight;
- this.location = location;
- friends = new String[]{"CHOI", "HAN"};
- }
- public Test02Person(int height, int weight, String location, String[] friends) {
- this.height = height;
- this.weight = weight;
- this.location = location;
- this.friends = friends;
- }
- }
- package test.com;
- public class Test02PersonMain {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- System.out.println("Person");
- Test02Person p = new Test02Person();
- System.out.println(p.height);
- System.out.println(p.weight);
- System.out.println(p.location);
- System.out.println(p.friends.length);
- System.out.println(p);
- for (int i = 0; i < p.friends.length; i++) {
- System.out.println(p.friends[i]);
- }
- System.out.println("==========================");
- Test02Person p2 = new Test02Person(170, 70, "Gangnam");
- System.out.println(p2.height);
- System.out.println(p2.weight);
- System.out.println(p2.location);
- System.out.println(p2.friends.length);
- System.out.println(p2);
- for (int i = 0; i < p2.friends.length; i++) {
- System.out.println(p2.friends[i]);
- }
- System.out.println("==========================");
- Test02Person p3 = new Test02Person(168, 50, "Guri", new String[]{"KIM","LEE","PARK","PARK2"});
- System.out.println(p3.height);
- System.out.println(p3.weight);
- System.out.println(p3.location);
- System.out.println(p3.friends.length);
- System.out.println(p3);
- for (String friend : p3.friends) {
- System.out.println(friend);
- }
- System.out.println("==========================");
- //p, p2, p3를 한꺼번에 갖는 배열을 작성하시오
- Test02Person[] ps = new Test02Person[3];
- ps[0] = p;
- ps[1] = p2;
- ps[2] = p3;
- //Test02Person[] ps = new Test02Person[]{p, p2, p3};
- System.out.println("키 몸무게 지역 친구수 친구리스트");
- for (int i = 0; i < ps.length; i++) {
- System.out.print(ps[i].height + " ");
- System.out.print(ps[i].weight + " ");
- System.out.print(ps[i].location + " ");
- System.out.print(ps[i].friends.length + " ");
- for (String friend : ps[i].friends) {
- System.out.print("["+friend + "]");
- }
- System.out.println();
- }
- System.out.println();
- } //end main
- } //end class
728x90
반응형
'JAVA > 6. Object2' 카테고리의 다른 글
오브젝트 예제 5 (0) | 2016.06.22 |
---|---|
오브젝트 예제 3 (class와 class 이용하여 배열처리) (0) | 2016.06.22 |
오브젝트 예제 1 (0) | 2016.06.22 |