简体   繁体   English

如何让程序能够获取用户输入的特殊字符的值

[英]How to make program can get the value of a special character that inputted by the user

so i want to make a program that can read special character and change it into other character using caesar chiper.所以我想制作一个可以读取特殊字符并使用凯撒芯片将其更改为其他字符的程序。 but, i don't understand how actually a special character can be read in java.但是,我不明白在 Java 中实际上如何读取特殊字符。 please teach me.请教我。 thank you.谢谢你。

Look at the Character class.查看 Character 类。 https://docs.oracle.com/javase/8/docs/api/java/lang/Character.html 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");
            }
        }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何获得该程序来计算用户输入单词中的元音? - How can I get this program to count the vowels in the User's inputted word? 如何检查用户输入的字符串(第一个字符串)中的字符是否存在于第二个字符串中? - How can I check if the character from a user- inputted string (first string) is present on the second string? 我怎样才能 append 根据用户输入的字母更改行的第一个和中间字符? - How can I append the first and middle character of a line that changes based on the letters that are inputted by the user? 如果用户输入了无效字符,我如何使我的程序向用户输出消息? - If a user inputs an invalid character how can I get my program to output a message to the user? 如何检查用户输入的内容是否是单词,而不是(* !?)之类的特殊字符? - How can I check if the user input is a word and not a special character like (*!?)? 如何获得程序以将每个字符打印为“字符1 :(字符),字符2 :(字符)等”? - How can I get my program to print out each character as “Character #1: (character) , Character #2: (character), etc”? 在java中的特殊字符之前获取string的值 - Get value of string before a special character in java 如果输入的数字不是一个快乐的数字,我怎么能得到一个假值? - How can i get a false value if the inputted number isn't a happy one? 除非在Java中输入更大的数字,否则如何将用户输入的数字放入双精度数 - How can I put an user inputted number to a double unless a bigger number is inputted in Java 将用户输入的整数转换为具有该 ASCII 码的字符 - Converting a user inputted integer to the character with that ASCII code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM