continueexample.java

来自「java程序设计 清华出版社 孙燮华老师编写的程序源代码」· Java 代码 · 共 19 行

JAVA
19
字号
//ContinueExample.java
public class ContinueExample{
  public static void main(String[] args){
    StringBuffer searchMe = new StringBuffer(
      "Peter Piper picked a peck of pickled peppers");
    int max = searchMe.length();
    int numPs = 0;
    for(int i = 0;i<max;i++){
      if(searchMe.charAt(i) != 'p')    //找出字符p
        continue;
      numPs++;                         //累加P的数目
      searchMe.setCharAt(i,'P');       //将'p'转换为'P'
    }
    System.out.println("Found " + numPs + " p's in the old string.");
    System.out.println("The new string is: "); 
    System.out.println(searchMe);
  }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?