exercise7_19.java

来自「Introduction to java programming 一书中所有编程」· Java 代码 · 共 26 行

JAVA
26
字号
// Exercise7_19.java: Write a program that passes a string as a
// command-line argument and displays the number of uppercase
// letters in the string.
public class Exercise7_19 {
  public static void main(String[] args) {
    // Check command-line arguments
    if (args.length != 1) {
      System.out.println(
        "Usage: java Exercise7_19 string");
      System.exit(0);
    }

    String s = args[0];
    int total = 0;

    for (int i = 0; i < s.length(); i++) {
      if (s.charAt(i) >= 'A' && s.charAt(i) <= 'Z')
        total++;
    }

    System.out.println("The number of uppercase letters is " +
      total);
  }
}

⌨️ 快捷键说明

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