This question has already been answered:

I work in NeatBeans

When I assign a value to a variable of type String in Russian, in the output window, instead of this, the values ​​show question marks:

ввод: русс вывод: ???? 

I changed the encoding from UTF-8 to windows-1251, but nothing has changed

here is the code

 Scanner input = new Scanner(System.in); System.out.print("ввод "); String s1 = input.nextLine(); System.out.print("\nВывод "+s1); 

UPD: There is a solution to the problem (you need to change something in the settings), but I do not remember it. A much better solution is to switch to IntelliJ IDEA.

Reported as a duplicate by Denis members, dirkgntly , Community Spirit 24 Aug '16 at 8:45 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

    1 answer 1

    To output string literals to the console correctly, when compiling, specify the encoding of the javac -encoding utf-8 Main.java source file.

    Input / output with the console under Windows is not a simple question, since the standard encoding of the operating system is cp1251, and the encoding of the console is cp866. Therefore, it is necessary to read the string in one encoding, and output to another:

     import java.util.Scanner; import java.nio.charset.Charset; public class Main { public static void main(final String args[]) throws java.io.UnsupportedEncodingException { System.out.print("ввод "); Scanner input = new Scanner(System.in, "Windows-1251"); //Считываем в кодировке операционной системы String s1 = input.nextLine(); String encoded = new String(s1.getBytes("windows-1251"), Charset.forName("cp866")); //Преобразуем в кодировку консоли System.out.println("\nВывод " + encoded); } }