[英]Why does this code print the ASCII value instead of the character
我以为将字符转换为char是我们能做到的,但它只会打印ascii值
String str = JOptionPane.showInputDialog("Enter a word");
str = str.toUpperCase();
String temp = "";
for(int i = 0 ; i < str.length() ; i++)
{
temp += (char)str.charAt(i) + 1;
}
System.out.println(temp);
您的错误是您将整数1添加到char中。 这将返回下一个字符的ASCII码。
改成
temp += (char)(str.charAt(i) +1)
您要加上+ 1,并导致将其转换为整数,我不确定是否正确解释了就将其删除
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.