Convert integer to character int j2me

雨燕双飞 提交于 2019-12-08 03:24:04

问题


I want to convert the integer into char.

Example:-

char c;
for(int i=0;i<10;i++){
    system.out.println(" char==="+c);
} 

I want to print the c as 0,1,2,3,4..... I had tried :-

c=(char)i; --gives error
c=97-i; -----gives a,b,c

回答1:


Use wrapper classes.

c = new Integer(i).toString().charAt(0);

by the way, you can also use this :

c = (char)(i + 48);



回答2:


Character.forDigit()

http://download.oracle.com/javase/6/docs/api/java/lang/Character.html



来源:https://stackoverflow.com/questions/6210901/convert-integer-to-character-int-j2me

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!