The program does not read the characters of the Kazakh language (instead of them there are question marks), for example, "ғ", while correctly displaying the characters of the Russian alphabet, as well as some characters like "љ". All of them are Cyrillic Unicode. I used windows-1251 encoding, tried setting UTF-8 in the project properties, but he refused to accept anything at all and just translated to a new line.

package la6; import java.io.UnsupportedEncodingException; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.Scanner; import java.util.Arrays; public class La6 { public static void main(String[] args) throws UnsupportedEncodingException { Scanner in = new Scanner(System.in, "windows-1251"); System.out.println("Enter ID's name: "); String str = in.nextLine(); if (isValidIdentifier(str)) { System.out.println("«" + str + "» - допустимое значение"); } else { System.out.println("«" + str + "» - недопустимое значение"); } System.out.println(); } public static boolean isValidIdentifier(String str) { if (!str.matches("[$_\u0401-\u04F9\u0041-\uFB06]+[$_0-9\u0401-\u04F9\u0041-\uFB06]+")) { return false; } String[] keyWords = {"boolean","volatile","else","instanceof","switch","true","goto","abstract","enum","int","static","false","break","assert","extends","interface","strictfp","null","continue","byte","final","long","super","do","case","finally","native","synchronized","double","catch","float","new","throw","protected","char","for","package","throws","this","class","if","private","transient","short","const","implements","public","try","while","default","import","return","void", "/", "\\","\""}; if (Arrays.asList(keyWords).contains(str)) { return false; } return true; } } 

Result:

 run: Enter ID's name: ырҒ «ыр?» - недопустимое значение 
  • Perhaps the font used does not contain the desired characters. Try changing the font. - Igor Kudryashov
  • @Igor Kudryashov Not That - Ted

1 answer 1

I tried to change the encoding in the project properties and add in the code itself - it did not help. In general, I decided this: Start the notebook on behalf of the admin -> move the folder where NetBeans is installed. And in this folder we move on to the etc directory, which will contain the netbeans.conf file. That is, the path to this file will be approximately as follows: C: \ Program Files \ NetBeans 8.1 \ etc \ netbeans.conf . In this file, we will change the parameter netbeans_default_options . By default, it has the following meaning:

 netbeans_default_options="-J-client -J-Xss2m -J-Xms32m -J-Dapple.laf.useScreenMenuBar=true -J-Dapple.awt.graphics.UseQuartz=true -J-Dsun.java2d.noddraw=true -J-Dsun.java2d.dpiaware=true -J-Dsun.zip.disableMemoryMapping=true" 

At the end add the option -J-Dfile.encoding=UTF-8 , do not forget to enter it under the quotes. That is, the result will be:

 netbeans_default_options="-J-client -J-Xss2m -J-Xms32m -J-Dapple.laf.useScreenMenuBar=true -J-Dapple.awt.graphics.UseQuartz=true -J-Dsun.java2d.noddraw=true -J-Dsun.java2d.dpiaware=true -J-Dsun.zip.disableMemoryMapping=true -J-Dfile.encoding=UTF-8" 
  • -J-Dfile.encoding=UTF-8 helped? - Igor Kudryashov
  • @Igor Kudryashov, yes - Ted