zoukankan      html  css  js  c++  java
  • Java Character 类

    Character 类用于对单个字符进行操作.

    Character 方法

    --------------------------------------------------------------------------

    Java isLetter() 方法  isLetter() 方法用于判断指定字符是否为字母

    例子:boolean isLetter(char ch) ch -- 要测试的字符 如果字符为字母,则返回 true;否则返回 false

    ---------------------------------------------------------------------------------------

    isDigit() 方法用于判断指定字符是否为数字。

    例子:public static boolean isDigit(char ch)  ch -- 要测试的字符。 如果字符为数字,则返回 true;否则返回 false
    ------------------------------------------------------------
    public class TestString {
    public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);
    String str = scanner.nextLine();
    char[] chars = str.toCharArray();
    int length = chars.length;
    System.out.println("length:"+length);
    if(length>0){
    System.out.println("该字符串"+str+"中的数字是:");
    for (int i = 0; i <chars.length; i++) {
    char aChar = chars[i];
    if(aChar!=' '){
    if (Character.isDigit(aChar)){
    System.out.print(aChar+",");
    }
    }
    }
    }
    }
    }
    --------------------------------------------------
    3dee4r4f 4ffd2s6g70b
    length:21
    该字符串3dee4r4f 4ffd2s6g70b中的数字是:3,4,4,4,2,6,7,0,
     
  • 相关阅读:
    USACO Section 1.4 Mother's Milk
    USACO Section 1.5 Checker Challenge
    USACO Section 1.5 Number Triangles
    九度 1140 八皇后
    九度 1091 棋盘游戏
    USACO Section 2.1 Sorting A ThreeValued Sequence
    USACO Section 1.4 The Clocks
    USACO Section 1.5 Superprime Rib
    USACO Section 2.1 Ordered Fractions
    双目测距与三维重建
  • 原文地址:https://www.cnblogs.com/2016-cxp/p/10922057.html
Copyright © 2011-2022 走看看