इस लेख में हम समझेंगे कि Java में दिए गए इंडेक्स पर यूनिकोड कोड पॉइंट कैसे निर्धारित किया जाता है। प्रत्येक कैरेक्टर को एक यूनिकोड कोड पॉइंट द्वारा दर्शाया जाता है। एक कोड पॉइंट एक पूर्णांक मान है जो दिए गए कैरेक्टर को विशिष्ट रूप से पहचानता है। यूनिकोड कैरेक्टर्स को विभिन्न एन्कोडिंग्स का उपयोग करके एन्कोड किया जा सकता है, जैसे UTF-8 या UTF-16।
उदाहरण
इनपुट:
Input String: Java Program Index value: 5
आउटपुट:
Unicode Point: 80
एल्गोरिदम
- शुरुआत
- एक स्ट्रिंग मान
input_stringऔर दो इंटीजर मानindexऔरresultडिक्लेयर करें - मान परिभाषित करें
- कोड पॉइंट वैल्यू प्राप्त करने के लिए
codePointAt()फंक्शन का उपयोग करें। मान को रिजल्ट के रूप में स्टोर करें - परिणाम प्रदर्शित करें
- रोकें
उदाहरण 1: मुख्य फंक्शन में सभी ऑपरेशन
import java.io.*;
public class UniCode {
public static void main(String[] args) {
System.out.println("Required packages have been imported");
String input_string = "Java Program";
System.out.println("\nThe string is defined as: " + input_string);
int result = input_string.codePointAt(5);
System.out.println("The unicode point at index 5 is : " + result);
}
}
आउटपुट
Required packages have been imported The string is defined as: Java Program The unicode point at index 5 is : 80
उदाहरण 2: ऑब्जेक्ट-ओरिएंटेड दृष्टिकोण
import java.io.*;
public class UniCode {
static void unicodeValue(String input_string, int index) {
int result = input_string.codePointAt(index);
System.out.println("The unicode point at index " + index + " is : " + result);
}
public static void main(String[] args) {
System.out.println("Required packages have been imported");
String input_string = "Java Program";
System.out.println("\nThe string is defined as: " + input_string);
int index = 5;
unicodeValue(input_string, index);
}
}
आउटपुट
Required packages have been imported The string is defined as: Java Program The unicode point at index 5 is : 80