The code was written, but characters are output to the console when using Cyrillic.

Symbols:

enter image description here

Code:

import java.util.Scanner; public class Pyatnadcat2 { public static void main(String[] args) { Scanner in = new Scanner(System.in); String s = in.nextLine(); System.out.println(capitalize(s)); } static String capitalize(String s){ char[] arr = s.toCharArray(); boolean inWord = false; for (int i = 0; i< arr.length; i++) { if (arr[i] >= 97 && arr[i] <= 122) { if (inWord) { continue; } arr[i] -= 32; inWord = true; } else { inWord = false; } } return new String(arr); } } 

    2 answers 2

    First, in NetBeans, you need to change the project encoding to utf-8:

    Right click on the project - properties -> image: enter image description here

    The next point (or remark?):

    You enter the Russian letters in the console, and in the method check the Latin lowercase:

    the digit in the html-code of the symbol - this is this symbol in Java that you check (97-122 range) (* someone, for God's sake, edit and write correctly) enter image description here

    And this means that your code works in such a way that you enter the Cyrillic alphabet - and output the same Cyrillic alphabet, without manipulations.

    ps In general, it is better to use the built-in toUpperCase method and not to bother with this;)

    • thanks) I will know) - Marat Zimnurov

    Instead of a dense type code:

     if (arr[i] >= 97 && arr[i] <= 122) 

    Normal methods of the type must be used: Character.isLowerCase(arr[i]) , and dislocation arr[i] -= 32 is treated by the method: Character.toUpperCase(arr[i])

    In general, a professional approach is to use an external library, for example Apache Commons-Lang, where such things have long been licked and worked out.

    • Thank you! I just started doing it, because I don’t know)) - Marat Zimnurov