怎樣在java中實(shí)現(xiàn)整型轉(zhuǎn)字符型?
代碼示例:
public class lanqiao1 {
public static void main(String[] args) {
//整型——>字符型
int i=5;
System.out.println((char)(i+'0'));//或者(char)(i+48)
//字符型——>整型
char j ='5';
System.out.println((int)(j-'0'));//或者(char)(j-48)
}
}
資料:
1.整型轉(zhuǎn)換成字符型
String num = Integer.toString(int n);
2.Long型轉(zhuǎn)換成字符型
String num = Long.toString(long n);
3.Short型轉(zhuǎn)換成字符型
String num = Short.toString(Short n);
4.Float型轉(zhuǎn)換成字符型
String num = Float.toString(Float n);