如何在我的 java 类中显示卢比符号?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30635605/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-11-02 17:25:16  来源:igfitidea点击:

How to display rupee symbol in my java class?

java

提问by Lakshmi Prasanna

if(this.currency.equalsIgnoreCase("?")) {
    r="? "+r;
}

I want to compare ?(Indian rupee symbol) in java. Here I am trying to print currency rupee symbol, but instead it is displaying the symbol like a?1.

我想?在 java 中比较(印度卢比符号)。在这里,我试图打印货币卢比符号,但它显示的是像a?1.

How to overcome this problem?

如何克服这个问题?

回答by CoderNeji

You can try with:

您可以尝试:

if(this.currency.equals("\u20B9")) {
    r="? "+r;
}

"\u20B9"is the java encoding for rupee symbol.

"\u20B9"是卢比符号的java编码。

More info:

更多信息:

回答by Umberto Raimondi

Your problem seems to be not much about the compare part of that snippet but mainly related to the printing, to display that characters correctly wrap System.outin an OutputPrintWriterwith an UTF-8 encoding, it's needed on some OS configuration:

您的问题似乎与该片段的比较部分无关,但主要与打印有关,要显示该字符正确包装System.outOutputPrintWriterUTF-8 编码中,某些操作系统配置需要它:

OutputStreamWriter stdOut=new OutputStreamWriter(System.out,"UTF8");
stdOut.println("?");

回答by Chandu D

    String string = "\u20B9";
    byte[] utf8 = string.getBytes("UTF-8");

    string = new String(utf8, "UTF-8");
    System.out.println(string);

回答by Vijay

  • Enable "UTF-8" in your editor (eclipse/netbean)
  • Or use unicode ("\u20B9").
  • 在编辑器中启用“UTF-8”(eclipse/netbean)
  • 或者使用 unicode ("\u20B9")。

回答by Chandu D

Try this:

试试这个:

String s="?";

if(s.equalsIgnoreCase("?")) {
  System.out.println("if condition"+s);
}