The program takes a string str1, copies its content to another string str2 using recursion, and then prints both strings. Here's a step-by-step explanation of how the program works:
class CopyString { public static void main(String[] args) { char str1[] = "Java Exercises".toCharArray(); char str2[] = new char[str1.length]; int index = 0; string_copy(str1, str2, index); System.out.println("String 1 : "+String.valueOf(str2)); System.out.println("String 2 : "+String.valueOf(str1)); } static void string_copy(char str1[],char str2[], int index) { str2[index] = str1[index]; if (index == str1.length - 1) { return; } string_copy(str1, str2, index + 1); } }
String 1 : Java Exercises String 2 : Java Exercises
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions