Write a Java program to get the character at the given index within the String.
Java Programming Language / StringBuffer Class Methods
7212Program:
public class Exercise1 { public static void main(String[] args) { String str = "Java Exercises!"; System.out.println("Original String = " + str); // Get the character at positions 0 and 10. int index1 = str.charAt(0); int index2 = str.charAt(10); // Print out the results. System.out.println("The character at position 0 is " + (char)index1); System.out.println("The character at position 10 is " + (char)index2); } }
Output:
Original String = Java Exercises! The character at position 0 is J The character at position 10 is i
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.
# C Tutorials
# JAVA Tutorials
# HTML Tutorials
# Computer Fundamental
# Data Structure
# DBMS Tutorials
SQL
# C# Language
# R Language
# PHP
# Python
# Vue JS