Home / Programs / Write a Java program to get the character (Unicode code point) before the specified index within the String.
🚀 Programming Example

Write a Java program to get the character (Unicode code point) before the specified index within the String.

👁 1,553 Views
💻 Practical Program
📘 Step Learning
Write a Java program to get the character (Unicode code point) before the specified index within the String.

💻 Program Code

public class Exercise2 {

   public static void main(String[] args) {

    String str = "atnyla.com";
    System.out.println("Original String : " + str);

    // codepoint before index 1
    int val1 = str.codePointBefore(1);

   // codepoint before index 9
    int val2 = str.codePointBefore(9);

    // prints character before index1 in string
    System.out.println("Character(unicode point) = " + val1);
    // prints character before index9 in string
    System.out.println("Character(unicode point) = " + val2);
  }
}

                        

🖥 Program Output

Original String : atnyla.com
Character(unicode point) = 97
Character(unicode point) = 111
Press any key to continue . . .
                            

📘 Explanation

None
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.