-2

I'm working on a small program that includes temperature displays. I want to have it display the degree symbol(°) next to the temperature, and the current code does that properly when I run it inside of my IDE(IntelliJ), but as soon as I try to run it from the command line, it isn't visible.

The print statement is written as follows:

System.out.println("The current temperature is " + currentTemp +"\u00B0");

Again, it displays properly in IntelliJ, but when I try to run it from a default command prompt, it doesn't have the degree symbol.

I'm using Java 14.0.1, Windows 10 version 1909. Let me know if any other information would help

John Kugelman
  • 349,597
  • 67
  • 533
  • 578
  • What exactly is `currentTemp`? Post an [MCVE](https://stackoverflow.com/help/mcve) when asking for debugging assistance. – Basil Bourque Jun 01 '20 at 23:14
  • 1
    Possibly, this Q/A [https://stackoverflow.com/questions/49016189/windows-10-cli-utf-8-encoding](https://stackoverflow.com/questions/49016189/windows-10-cli-utf-8-encoding) may solve your problem? – Ivo Mori Jun 01 '20 at 23:15
  • Your code [runs successfully in IdeOne.com](https://ideone.com/5hBs9k). – Basil Bourque Jun 01 '20 at 23:16

1 Answers1

-1

You can try this :

PrintStream out = new PrintStream( System.out, true );
out.println("The current temperature is "+currentTemp  + "\u00B0" + "C" );

The ouput :

enter image description here

Pluto
  • 853
  • 1
  • 8
  • 28