在JAVA输入一个数字 输出他在Unicode表中对应的字符 5
怎样实现?下面这段代码为什么不对importjava.util.*;publicclassS{publicstaticvoidmain(Stringargs[]){Sca...
怎样实现?
下面这段代码为什么不对
import java.util.*;
public class S{
public static void main (String args[]){
Scanner rd=new Scanner(System.in);
int s=rd.NextInt();
char a;
a=s;
System.out.println(a);
}
} 展开
下面这段代码为什么不对
import java.util.*;
public class S{
public static void main (String args[]){
Scanner rd=new Scanner(System.in);
int s=rd.NextInt();
char a;
a=s;
System.out.println(a);
}
} 展开
展开全部
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class UnicodeDemo {
public static void main(String[] args) throws IOException {
//String s="sdjakjdkl";
//键盘录入
while(true)
{
BufferedReader bufr = new BufferedReader(new InputStreamReader(System.in));
String s=bufr.readLine();//.toString();
if("over".equals(s)){
break;
}
String u=string2Unicode(s);
System.out.println(u);
}
}
public static String string2Unicode(String string) {
StringBuffer unicode = new StringBuffer();
for (int i = 0; i < string.length(); i++) {
// 取出每一个字符
char c = string.charAt(i);
// 转换为unicode
unicode.append("\\u" + Integer.toHexString(c));
}
return unicode.toString();
}
}
import java.io.IOException;
import java.io.InputStreamReader;
public class UnicodeDemo {
public static void main(String[] args) throws IOException {
//String s="sdjakjdkl";
//键盘录入
while(true)
{
BufferedReader bufr = new BufferedReader(new InputStreamReader(System.in));
String s=bufr.readLine();//.toString();
if("over".equals(s)){
break;
}
String u=string2Unicode(s);
System.out.println(u);
}
}
public static String string2Unicode(String string) {
StringBuffer unicode = new StringBuffer();
for (int i = 0; i < string.length(); i++) {
// 取出每一个字符
char c = string.charAt(i);
// 转换为unicode
unicode.append("\\u" + Integer.toHexString(c));
}
return unicode.toString();
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询