所以我想创建一个可以读取特殊字符的程序,并使用caesar chiper将其更改为其他字符。但是,我不明白如何在java中读取特殊字符。请教我。谢谢。
答案 0 :(得分:0)
查看Character类。 https://docs.oracle.com/javase/8/docs/api/java/lang/Character.html
char[] charArray = {'1', ' ', '!', 'a', 'C'};
for (int i = 0; i < charArray.length; i++) {
char c = charArray[i];
if(Character.isWhitespace(c)) {
System.out.println( "'" + c +"'" + " is whitespace");
} else if (Character.isDigit(c)) {
System.out.println( "'" + c +"'" + " is a number");
} else if (Character.isLetter(c)) {
System.out.println( "'" + c +"'" + " is a letter");
} else {
System.out.println( "'" + c +"'" + " must be a special character");
}
}