Write and test your own code of the following function: void getChars(String src
ID: 3686922 • Letter: W
Question
Write and test your own code of the following function: void getChars(String src, int srcBegin, int srcEnd, char[] dest, int destBegin) This function copies the characters of String src to the dest array Only the specified range is being copied (srcBegin to srcEnd) to the dest subarray (starting fromdestBegin). String replace (String src. char oldChar. char newChar) This function returns the new updated string after changing all the occurrences of oldChar with the newChar. String toUpperCase(String src) Converts the string to upper Case string (all letter* are uppercase),Explanation / Answer
1. import java.io.UnsupportedEncodingException;
public class Program
{
public static void main(String[] args)
{
String str = "This is a String.";
char[] arr = new char[] { ' ', ' ', ' ', ' ',
' ', ' ', ' ', ' ' };
str.getChars(5, 10, arr, 3);
System.out.println("The char array equals "" +
arr + """);
}
}
Output:
The char array equals " is a "
2.
public class JavaStringReplaceExample{
public static void main(String args[])
{
String str="Replace Region";
System.out.println( str.replace( 'R','A' ) );
System.out.println( str.replaceFirst("Re", "Ra") );
System.out.println( str.replaceAll("Re", "Ra") );
}
}
OUTPUT
Aeplace Aegion
Raplace Region
Raplace Ragion
3.
class ChangeCase {
public static void main(String args[])
{
String s = "This is a test.";
System.out.println("Original: " + s);
String upper = s.toUpperCase();
System.out.println("Uppercase: " + upper);
}
}
O/P:
Original: This is a test.
Uppercase: THIS IS A TEST.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.