ASCII码值与字符的相互转换
前⾔
ASCII(American Standard Code for Information Interchange,美国信息交换标准代码)是基于拉丁字母的⼀套电脑编码系统,主要⽤于显⽰现代英语和其他西欧语⾔。它是现今最通⽤的单字节编码系统,并等同于国际标准ISO/IEC 646。在编程中可以借助ASCII编码的字符解决⼀些常见的问题。
望的组词
字符转ASCII码medium什么意思
/**
* 字符转ASCII码
* @param n朴素的近义词
* @return
*/
public static int getASCII(char n){
2021年国庆节int ascii = n;
return ascii;
}
ASCII码转字符
/**
* 根据ASCII码获取对应的字符江苏牧医学院
* @param n
* @return
*/
public static char getChar(int n){炒胡萝卜丝
char c = (char) n;
return c;
}
测试
public static void main(String[] args) {
// 获取A的ASCII码怎样清理热水器
System.out.println("字符A对应的ASCII码是:"+ getASCII('A'));
// 根据ASCII码获取对应的字符
System.out.println("65对应的字符是:"+ getChar(65));
}
结果如下:
/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home/bin/java -javaagent:/Application
s/IntelliJ IDEA.app/Contents/lib/idea_rt.jar=52600:/Appli cations/IntelliJ IDEA.app/Contents/bin -ding=UTF-8 -classpath /Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home/jre/lib/chart s.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home/jre/lib/deploy.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Ho me/jre/lib/ext/cldrdata.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home/jre/lib/ext/dnsns.jar:/Library/Java/JavaVirtualMachines/jdk1.8. 0_221.jdk/Contents/Home/jre/lib/ext/jaccess.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home/jre/lib/ext/jfxrt.jar:/Library/Java/JavaVirt ualMachines/jdk1.8.0_221.jdk/Contents/Home/jre/lib/ext/localedata.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home/jre/lib/ext/nasho rn.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home/jre/lib/ext/sunec.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents /Home/jre/lib/ext/sunjce_provider.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home/jre/lib/ext/sunpkcs11.jar:/Library/Java/JavaVirtual Machines/jdk1.8.0_221.jdk/Contents/Home/jre/lib/ext/zipfs.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home/jre/lib/javaws.jar:/Library/ Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home/jre/lib/jce.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home/jre/lib/jfr.jar:/L ibrary/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home/jre/lib/jfxswt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home/jre/li b/js.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home/jre/lib/management-agent.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_22 1.jdk/Contents/Home/jre/lib/plugin.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home/jre/lib/resources.jar:/Library/Java/JavaVirtualMac hines/jdk1.8.0_221.jdk/Contents/Home/jre/lib/rt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home/lib/ant-javafx.jar:/Library/Java/Java VirtualMachines/jdk1.8.0_221.jdk/Contents/Home/lib/dt.jar:/Library/Java/
JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home/lib/javafx-mx.jar:/Library/Jav a/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home/lib/jconsole.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home/lib/packager.ja r:/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home/lib/sa-jdi.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_221.jdk/Contents/Home/lib/to ols.jar:/Urs/legend/Documents/Work/Project/MyTestProject/out/production/MyTestProject:/Urs/legend/.m2/repository/junit/junit/4.12/junit-4.12.jar:/Ur s/legend/.m2/repository/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar Demo.AsciiTest
字符A对应的ASCII码是:65
65对应的字符是:A
把握当下作文
Process finished with exit code 0