📄 charmethods.java
字号:
import java.io.*;
public class CharMethods
{
public static void main (String[] args)
{
String str = new String("This -123/ is 567 A ?<6245> Test!");
char nextChar;
int i, numChars;
int numLetters = 0, numDigits = 0, numOthers = 0;
System.out.println("The original string is: " + str);
numChars = str.length();
System.out.println("This string contains " + numChars + " characters,"
+ " which consists of");
// check each character in the string
for (i = 0; i < numChars; i++)
{
nextChar = str.charAt(i); // get a character
if (Character.isLetter(nextChar))
numLetters++;
else if (Character.isDigit(nextChar))
numDigits++;
else
numOthers++;
}
System.out.println(" " + numLetters + " letters");
System.out.println(" " + numDigits + " digits");
System.out.println(" " + numOthers + " other characters.");
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -