我想显示希腊unicode字符,但显示“?".代替输出 [英] I want to display Greek unicode characters but i get "?" instead on ouput

查看:61
本文介绍了我想显示希腊unicode字符,但显示“?".代替输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要从Java中以字母开头打印n个希腊字符(带有"\ u03B1"代码).这是我的初衷:

I want to print n Greek characters in Java starting from alpha (whitch has the "\u03B1" code).This is what I had in mind:

String T = "";
  for(int i = 0,aux = 0;i<n;i++)
       {
           aux = '\u03B1' + i;
           T +=Character.toString((char)aux);
       }
  System.out.println(T);

但是它会打印n个问号.

But it prints n question marks instead.

比方说,n = 3,在输出中我得到"???".

Let's say n=3,on the output i get "???".

我认为也许我的方法是错误的,但是如果我尝试这样的话又会再次出现:

I thought that maybe my method is wrong but then again if I try something like this:

System.out.println("\u03B1\u03B2\u03B3");

我得到相同的输出:"???"

I get the same output:"???"

为什么我得到此输出而不是所需的字符?如何打印我想要的字符?

Why do I get this output instead of the desired characters and how can I print them like I want to?

注意:我使用IntelliJ作为IDE,并且我的操作系统是Windows 10.

Note:I use IntelliJ as IDE and my OS is Windows 10.

推荐答案

您会收到无效的字符输出,因为IDE的控制台输出(可能)设置为Windows默认字符集编码, Unicode 编码.

You get the invalid character output because the console output of your IDE is (probably) set to Windows default charset encoding, CP-1252, but Java natively uses Unicode encoding.

要解决此问题,您应该将IDE控制台输出的字符集编码设置为UTF-8,例如通过使用此帖子中的说明.

To fix the problem, you should set the charset encoding of your IDE's console output to UTF-8, e.g. by using the instructions from this post.

这篇关于我想显示希腊unicode字符,但显示“?".代替输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆