Java: Count a number of Unicode code points in the specified text range of a String
4. Count Unicode Points in Range
Write a Java program to count Unicode code points in the specified text range of a string.
Sample Solution:
Java Code:
// Define a public class named Exercise4.
public class Exercise4 {
// Define the main method.
public static void main(String[] args) {
// Declare and initialize a string variable "str" with the value "w3rsource.com".
String str = "w3rsource.com";
// Print the original string.
System.out.println("Original String : " + str);
// Count the number of Unicode code points from index 1 to index 10 in the string.
int ctr = str.codePointCount(1, 10);
// Print the count of Unicode code points from index 1 to index 10 in the string.
System.out.println("Codepoint count = " + ctr);
}
}
Sample Output:
Original String : w3rsource.com Codepoint count = 9
Flowchart:
For more Practice: Solve these Related Problems:
- Write a Java program to count and display the number of Unicode code points in a specified substring range.
- Write a Java program that accepts a string and two indices, then computes the total Unicode value sum within that range.
- Write a Java program to count Unicode code points in a string region while skipping digits.
- Write a Java program to verify if the count of Unicode code points in a substring range matches a user-specified number.
Go to:
PREV : Get Unicode Code Point Before Index.
NEXT : Lexicographical String Comparison.
Java Code Editor:
Improve this sample solution and post your code through Disqus
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.