Friday, August 30, 2024

Javamy

import java.lang.*; class STR { // Function to insert string public static String insertString( String originalString, String stringToBeInserted, int index) { // Create a new string String newString = new String(); for (int i = 0; i < originalString.length(); i++) { // Insert the original string character // into the new string newString += originalString.charAt(i); if (i == index) { // Insert the string to be inserted // into the new string newString += stringToBeInserted; } } // return the modified String return newString; } // Driver code public static void main(String[] args) { String originalString = "Hello, world!"; String stringToBeInserted = " there"; int index = 6; String modifiedString = insertString(originalString, stringToBeInserted, index); System.out.println("Modified string: " + modifiedString); } }

No comments:

Post a Comment

please do not enter any spam link in the comment .

New Post

Javamy

import java.lang.*; class STR { // Function to insert string public static String insertString( String originalString, ...