Strange characters when entering Russian letters (Cyrillic) in Java

import java.util.Scanner;

public static void main(String[] args) {
     Scanner n = new Scanner (System.in);
     String fio;
     System.out.print("Введите Фамилию :");
     fio = n.nextLine();
     System.out.println(fio);
}

Enter Your Last Name: Denis Ivanov
������ ����� ��������
BUILD COMPLETED SUCCESSFULLY (total time: 19 seconds)

When you enter Russian letters, it outputs incomprehensible characters. How to fix it? Tell me, if you can, example, I work in NetBeans IDE 8.0.1.

Author: Denis, 2015-01-25

2 answers

Your problem is described here.

If you write in NetBeans, then you need to go to the project properties and change the encoding to windows-1251. After that, this code works correctly:

enter a description of the image here


Or alternatively specify the encoding of the characters you enter immediately:

public static void main(String[] args) throws UnsupportedEncodingException, IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in,"Cp1251"));
    System.out.println("Введите ФИО:");
    //Scanner in = new Scanner(System.in);
    String s = br.readLine();
    System.out.println(s);
}
 4
Author: Denis, 2016-07-11 07:45:26

If you write in Netbeans -

Scanner scanner = new Scanner (System.in, "Cp866");

It will read Russian letters without any problems.

 1
Author: Иван, 2018-08-02 10:15:21