Java
 Computer >> コンピューター >  >> プログラミング >> Java

特定のインデックスでUnicodeコードポイントを決定するJavaプログラム


この記事では、特定のインデックスでユニコードコードポイントを決定する方法を理解します。各文字は、ユニコードコードポイントで表されます。コードポイントは、指定された文字を一意に識別する整数値です。 Unicode文字は、UTF-8やUTF-16などのさまざまなエンコーディングを使用してエンコードできます。

以下は同じのデモンストレーションです-

入力がであると仮定します −

Input String: Java Program
Index value: 5

必要な出力は

Unicode Point: 80

アルゴリズム

Step 1 - START
Step 2 - Declare a string value namely input_string and two integer values namely index and result
Step 3 - Define the values.
Step 4 - Use the function codePointAt() to fetch the code point value. Store the value as result.
Step 5 - Display the result
Step 6 - Stop

例1

ここでは、「main」関数の下ですべての操作をバインドします。

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 unicode_value(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;
      unicode_value(input_string, index);
   }
}

出力

Required packages have been imported

The string is defined as: Java Program
The unicode point at index 5is : 80

  1. 台形の領域を見つけるJavaプログラム

    この記事では、台形の領域を見つける方法を理解します。台形は、少なくとも1対の辺が互いに平行な四辺形の一種です。台形の平行な側面はベースと呼ばれ、台形の非平行な側面は脚と呼ばれます。台形とも呼ばれます。 台形の面積は、式-を使用して計算されます。 (height/2 * (side_1 + side_2). i.e. Area = ½ x (sum of the lengths of the parallel sides) x perpendicular distance between parallel sides 以下は同じもののデモンストレーションです。平行な辺aとbの長

  2. 長方形の周囲を見つけるJavaプログラム

    この記事では、長方形の周囲を見つける方法を理解します。長方形の周囲長は、長方形のすべての辺の長さを加算して計算されます。 以下は長方形のデモンストレーションです。長方形の周囲は、長方形の2つの長さと2つの幅の全長です- 入力 入力が-であると仮定します The length of the sides of a rectangle are : 5, 8, 5, 8 出力 必要な出力は-になります Perimeter : 26 アルゴリズム Step 1 – START Step 2 – Declare 5 floating point variabl