| 일 | 월 | 화 | 수 | 목 | 금 | 토 | 
|---|---|---|---|---|---|---|
| 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 | 31 | 
- '티스토리 초대장/ 티스토리초대'
- GitHub 미러링
- Emmet
- settings sync
- 실행시간 측정
- gitlab 연동
- 티스토리초대
- GitLab Mirroring
- 네이버 클라우드 플랫폼
- visual studio code
- 음료같은녹즙
- code 설치
- eslint-import-resolver-typescript
- 초대장
- GitHub Mirroring
- webstorm
- code 세팅
- visual studio code cli
- react native #gradle
- React Native
- 유니옥션
- code .
- Path Alias
- 프레시업 #풀무원 #하루한병 #건강만들기 #풀무원 녹즙
- 니돈내먹
- 티스토리 초대장/ 티스토리초대
- currentTimeMillis
- 티스토리 초대장
- GitLab미러링
- 프리티어
- Today
- Total
방치하기
홍대 수업 자바 한글 스트링 인식해서 갯수 세주기 str.getBytes().length; 본문
abstract class AbstractDisplay { 
    public abstract void open();        
    public abstract void print();       
    public abstract void close();       
    public final void display() {       
        open();                         
        for (int i = 0; i < 5; i++) {   
            print();                    
        }
        close();                        
    }
}
 class CharDisplay extends AbstractDisplay {  
    private char ch;                                
    public CharDisplay(char ch) {                   
        this.ch = ch;                               
    }
    public void open() {                            
        System.out.print("<<");                     
    }
    public void print() {                           
        System.out.print(ch);                       
    }
    public void close() {                           
        System.out.println(">>");                   
    }
}
class StringDisplay extends AbstractDisplay {  
    private String str;
 int width;
    public StringDisplay(String str) {                   
        this.str = str;                               
  width=str.getBytes().length; //한글 스트링이 자리 두개씩 차지해서 이걸 써야함 .. 
    }
    public void open() {    
  System.out.print("+");
  for (int i=0; i<width ;i++ )
       {
     System.out.print("-");
       }
 System.out.println("+");                           
 }                     
   
  
                          
    
    public void print() {                           
        System.out.println("|"+ str+"|");                       
    }
    public void close() {       
   System.out.print("+");
       for (int i=0; i<width ;i++ )
       {
     System.out.print("-");
       }
  System.out.println("+");                          
 }                     
   
  
}
public class Main {
    public static void main(String[] args) {
        AbstractDisplay d1 = new CharDisplay('H');                  
        AbstractDisplay d2 = new StringDisplay("Hello, world.");    
        AbstractDisplay d3 = new StringDisplay("안녕하세요.");     
        d1.display();                                               
        d2.display();                                               
        d3.display();                                               
    }
}
'홍익대 Java > 수업' 카테고리의 다른 글
| 홍대 자바 수업 : 객체의 수를 제한하는 방법론적. (0) | 2009.07.24 | 
|---|---|
| 홍대 자바 수업 .도서관 객체 . 인터페이스 와 상속 (0) | 2009.07.24 | 
| 홍대 자바 수업 : 강제적 업캐스팅 (0) | 2009.07.23 | 
| 홍대 자바 수업 : 상속 관계인지 확인 instanceof (0) | 2009.07.23 | 
| 홍대 자바 수업: 클래스 상속 . (0) | 2009.07.23 | 
