This program takes a string and returns a new string with each character repeated twice. Here's how it works:
In the main method, an instance of the Repeating_Char class is created, and the repeat method is called with the input string "Java". The resulting string, with each character repeated twice, is then printed to the console.
public class Repeating_Char { public String repeat(String str) { int l = str.length(); String new_str = ""; for (int i = 0; i < l; i++) { new_str += str.substring(i,i+1) + str.substring(i, i+1); } return new_str; } public static void main (String[] args) { Repeating_Char m= new Repeating_Char(); String str = "Java"; System.out.println("Given string : "+str); System.out.println("Repeating Every Character in String : "+m.repeat(str)); } }
Given string : Java Repeating Every Character in String : JJaavvaa
Learn All in Tamil © Designed & Developed By Tutor Joes | Privacy Policy | Terms & Conditions