黑马程序员技术交流社区
标题:
java中如何将 ASC码转换成字符?
[打印本页]
作者:
qushuai
时间:
2013-7-22 09:46
标题:
java中如何将 ASC码转换成字符?
本帖最后由 qushuai 于 2013-7-22 10:44 编辑
如题 js 中貌似可以用 String.fromCharCode()方法 Java中怎么弄,查了半天api 无解
作者:
qushuai
时间:
2013-7-22 10:37
解决了。忘了强转这一说。 将ASC 码值 强转 成char 就好了。 char(ASC)
作者:
tonygone
时间:
2013-7-22 10:38
题目没看明白,大小写转换吗?
//大写转小写
public char upp2low(char upp){
return (char)(upp+32);
}
//小写转大写
public char low2upp(char low){
return (char)(low+32);
}
复制代码
作者:
qushuai
时间:
2013-7-22 10:41
tonygone 发表于 2013-7-22 10:38
题目没看明白,大小写转换吗?
哦 不是 是 生成 一个 随机数 然后将这些作为 ASC 码 转换成相应的字符。
long tempRandom = Math.round(Math.random()*3);
if(tempRandom == 0)
{
long Rnum = Math.round(Math.random()*9 + 48);
return ""+(char)Rnum;
}
不加那个强转的 话 返回的 是一个数字。
作者:
陌路行者
时间:
2013-7-22 10:46
tonygone 发表于 2013-7-22 10:38
题目没看明白,大小写转换吗?
大小写转换用 toUpperCase 和 toLowerCase
作者:
tanzhiqiu
时间:
2013-7-22 10:51
大小写转换用 toUpperCase 和 toLowerCase
作者:
xwf4348
时间:
2013-7-22 11:16
强制转换(char)ASC
作者:
深圳在漂移
时间:
2013-7-22 11:24
public class ASCTest { private static int ascNum; private static char strChar; public static void main(String[] args) { System.out.println(getAsc("a")); System.out.println(backchar(98)); } /** * 字符转ASC * * @param st * @return */ public static int getAsc(String st) { byte[] gc = st.getBytes(); ascNum = (int) gc[0]; return ascNum; } /** * ASC转字符 * * @param backnum * @return */ public static char backchar(int backnum) { strChar = (char) backnum; return strChar; }}
复制代码
ASC码转字符
作者:
王丽达
时间:
2013-7-22 12:08
class ASCTest
{
private static char getChar;
public static void main(String[] args)
{
//打印传入的ASC
System.out.println(backChar(77));
}
//定义转换ASC的方法
public static char backChar(int ascnum)
{
//将ASC强转成char
getChar = (char)ascnum;
return getChar;
}
}
复制代码
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/)
黑马程序员IT技术论坛 X3.2