- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要打印除字母以外的所有字符。 (逗号、空格等)并显示它们。这是到目前为止的代码,
public static void main(String[] args)
{
String a = "elephant";
String b = "ElEphAnt";
String c = "This is a string.";
String d = "i R gr8, u R gr8";
int ucounter = 0;
int lcounter = 0;
int dcounter = 0;
int ocounter = 0;
for (int i = 0; i < a.length(); i++)
{
if (Character.isUpperCase(a.charAt(i)))
ucounter++;
if (Character.isLowerCase(a.charAt(i)))
lcounter++;
if (Character.isDigit(a.charAt(i)))
dcounter++;
}
System.out.println("String: " + a );
System.out.println("\n");
System.out.println("\tlowercase: %d, uppercase: %d, digit: %d, other: " +ucounter);
}
我在让他们在计算数字后打印出数字时遇到了一个小问题,但这是我将自己解决的一个单独问题。我仔细阅读了论坛,似乎无法找到如何计算空格和特殊字符的方法。为此,我只能使用 length()
和 charAt()
。特殊字符的 Character.is??
是什么?还是有一个?
最佳答案
不要只使用 if
,而是使用 if/else
组合,这样你就可以确保你总是只遇到 一个 匹配大小写。然后,使用 Character.isWhitespace
检测空白,最后使用 !Character.isLetter
(注意 !
)检测除字母以外的所有内容。
使用 if/else
执行此操作很重要,否则最后的测试也会匹配数字、逗号、空格等。
来自 java.lang.Character.isLetter 的类文档:
A character is considered to be a letter if its general category type, provided by getType(codePoint), is any of the following:
关于java - 在 Java 中计算字符以外的所有内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33051518/
我已经坚持了好几天了……很抱歉遇到这样的问题,但是我只是F#本身的初学者。由于关于类型提供程序的讨论很多,所以我决定建立一个类型提供程序并撰写一篇有关它的论文。当我开始时,我不知道什么是类型提供程序。
我正在开发LAN项目唤醒功能,但是我想控制局域网中计算机是否打开。但是我不想使用ICMP或WMI(我的网络上有DC)。那么,对于此问题,是否还有其他选择,例如“套接字连接”,请检查特定端口是否正在使用
我们有一个旧的VB6应用程序,该应用程序使用Crystal Reports XI生成打印报告。我们已经通过经验发现,如果Crystal Reports打印引擎选择了错误版本的 usp10.dll (W
我正在尝试获取有效的 Android 权限列表。我知道 http://developer.android.com/reference/android/Manifest.permission.html
嗨,我是 nginx 的新手,我试图在我的服务器(运行 Ubuntu 4)上设置它,它已经运行了 apache。 所以在我 apt-get install 它之后,我尝试启动 nginx。然后我收到这
如何在VB 6中检查对象的类型-除了'TypeName'之外,是否还有其他方法,因为无法通过'TypeName'进行检查,我希望使用类似QuichWatch窗口的方法。 最佳答案 对于对象变量,请使用
我的 JSP 应用程序中有一个错误。发布后我的 session 被清除: YAHOO.util.Connect.asyncRequest('POST', Url, callback, post
我是一名优秀的程序员,十分优秀!