复制字符串

public class WhileDemo {
    public static void main(String[] args) {

        String copyFromMe = "Copy this string until you encounter the letter 'g'.";
        StringBuffer copyToMe = new StringBuffer();

        int i = 0;
        char c = copyFromMe.charAt(i);

        while (c != 'g') {
            copyToMe.append(c);
            c = copyFromMe.charAt(++i);
        }
        System.out.println(copyToMe);
    }
}

posted @ 2013-07-18 15:03  elite_2012  阅读(238)  评论(0编辑  收藏  举报