ASCII编码
1.概述
2.ASCII表
3.示例代码
创建maven项目 encrypt-decrypt
添加pom文件
<dependencies>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
</dependencies>
创建类 com.atguigu.ascii.AsciiDemo
字符转换成ascii码
package com.atguigu.ascii;
/**
* AsciiDemo
*
* @Author: 尚硅谷
* @CreateTime: 2020-03-17
* @Description:
*/
public class AsciiDemo {
public static void main(String[] args) {
char a = 'A';
int b = a;
// 打印ascii码
System.out.println(b);
}
}
运行程序
字符串转换成ascii码
package com.atguigu.ascii;
/**
* AsciiDemo
*
* @Author: 尚硅谷
* @CreateTime: 2020-03-17
* @Description:
*/
public class AsciiDemo {
public static void main(String[] args) {
// char a = 'A';
// int b = a;
// System.out.println(b);
String a = "AaZ";
// 获取ascii码,需要把字符串转成字符
char[] chars = a.toCharArray();
for (char c : chars) {
int asciiCode = c;
System.out.println(asciiCode);
}
}
}
运行程序