package cn.edu.bjut.chapter2; public class ForExample { public static void main(String[] args) { String copyFromMe = "Copy every letter until you encounter 'u'."; // 给定字符串 StringBuffer copyToMe = new StringBuffer();// 创建一个空的串变量 int i; char c; for (i = 0, c = copyFromMe.charAt(i); i < copyFromMe.length() && c != 'u'; c = copyFromMe.charAt(++i)) { copyToMe.append(c); } System.out.println(copyToMe); } }