Write a java program to count a number of Unicode code points in the specified text range of a String.

Java Programming Language String in java (Article) String in java (Program)

1590

Program:

<span class="kwd">public</span><span class="pln"> </span><span class="kwd">class</span><span class="pln"> </span><span class="typ">Exercise</span><span class="pln"> </span><span class="pun">{</span><span class="pln">

 </span><span class="kwd">public</span><span class="pln"> </span><span class="kwd">static</span><span class="pln"> </span><span class="kwd">void</span><span class="pln"> main</span><span class="pun">(</span><span class="typ">String</span><span class="pun">[]</span><span class="pln"> args</span><span class="pun">)</span><span class="pln"> </span><span class="pun">{</span><span class="pln">

    </span><span class="typ">String</span><span class="pln"> str </span><span class="pun">=</span><span class="pln"> </span><span class="str">"atnyla.com"</span><span class="pun">;</span><span class="pln">
    </span><span class="typ">System</span><span class="pun">.</span><span class="kwd">out</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"Original String : "</span><span class="pln"> </span><span class="pun">+</span><span class="pln"> str</span><span class="pun">);</span><span class="pln">

    </span><span class="com">// codepoint from index 1 to index 10</span><span class="pln">
    </span><span class="kwd">int</span><span class="pln"> ctr </span><span class="pun">=</span><span class="pln"> str</span><span class="pun">.</span><span class="pln">codePointCount</span><span class="pun">(</span><span class="lit">1</span><span class="pun">,</span><span class="pln"> </span><span class="lit">10</span><span class="pun">);</span><span class="pln">

    </span><span class="com">// prints character from index 1 to index 10</span><span class="pln">
    </span><span class="typ">System</span><span class="pun">.</span><span class="kwd">out</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="str">"Codepoint count = "</span><span class="pln"> </span><span class="pun">+</span><span class="pln"> ctr</span><span class="pun">);</span><span class="pln">
  </span><span class="pun">}</span><span class="pln">
</span><span class="pun">}</span>

Output:

Original String : atnyla.com
Codepoint count = 9
Press any key to continue . . .

Explanation:

None

This Particular section is dedicated to Programs only. If you want learn more about Java Programming Language. Then you can visit below links to get more depth on this subject.