🔥 Welcome to Ashok IT..!! 👉 Register Here For Online Training : bit.ly/4dBYJbX 👉 Follow us in Instagram : bit.ly/3jzEKl8 👉 Follow Us in WhatsApp : bit.ly/49wCWje 👉 Visit Our Website : ashokit.in/
Sir, it was a great tutorial can you please help, one interview coding question which was based on String I was not able to solve that properly Input: abbcccdddd Output: ab2c3d4 If the repetition of a char in a string is more than one, then it should be replaced by a number denoting the occurrence of that char in String
Thank you sir.. I'm facing issue with if (input.indexOf(charToReplace == -1)) is not working... Error: The method indexOf(int) in the type String is not applicable for the arguments (boolean) Any one can help me with this plz.. Thanks
package StringQuestions; public class ReplaceCharWithCountOfRepetition { public static void main(String[] args) { String input = "opentext"; char chCheck = 't'; input = input.toLowerCase(); if (input.indexOf(chCheck) == -1) { System.out.println("The Given Character is not present!"); return; // Exit early if the character is not found } StringBuilder sb = new StringBuilder(input); int count = 1; for (int i = 0; i < sb.length(); i++) { if (sb.charAt(i) == chCheck) { sb.setCharAt(i, (char) ('0' + count)); count++; } } System.out.println(sb.toString()); } }
public static String Replace_occurances(String s,char rc) {
StringBuilder ans= new StringBuilder(); int count=1; if(s.indexOf(rc)==-1){ System.out.println("The given character "+rc+" is not present in the String"); }else{ for(int i=0;i
🔥 Welcome to Ashok IT..!!
👉 Register Here For Online Training : bit.ly/4dBYJbX
👉 Follow us in Instagram : bit.ly/3jzEKl8
👉 Follow Us in WhatsApp : bit.ly/49wCWje
👉 Visit Our Website : ashokit.in/
for(int i = 0 ; i
9:05 why this will not work, not clear, does it mean it will store only single char of integer like not greater than 0-9 ?
Nice. Kindly give data structure video also
Sir, it was a great tutorial can you please help, one interview coding question which was based on String I was not able to solve that properly
Input: abbcccdddd
Output: ab2c3d4
If the repetition of a char in a string is more than one, then it should be replaced by a number denoting the occurrence of that char in String
🔥 Please follow us in WhatsApp channel : bit.ly/49wCWje
string str = "opentext";
char ch = 't';
int count = 48;
char[] chars = str.ToCharArray();
for (int i = 0; i < chars.Length; i++)
{
if (ch == chars[i])
{
count++;
chars[i] = (char)count;
}
}
Console.WriteLine(chars);
🔥 Please follow us in WhatsApp channel : bit.ly/49wCWje
Thank you sir..
I'm facing issue with
if (input.indexOf(charToReplace == -1)) is not working...
Error: The method indexOf(int) in the type String is not applicable for the arguments (boolean)
Any one can help me with this plz..
Thanks
Please contact our admin team : 9985396677
What would happen if we just did it as arr[i] = String.valueOf(cnt); ?
please contact our admin team : +91 9985396677
package StringQuestions;
public class ReplaceCharWithCountOfRepetition {
public static void main(String[] args) {
String input = "opentext";
char chCheck = 't';
input = input.toLowerCase();
if (input.indexOf(chCheck) == -1) {
System.out.println("The Given Character is not present!");
return; // Exit early if the character is not found
}
StringBuilder sb = new StringBuilder(input);
int count = 1;
for (int i = 0; i < sb.length(); i++) {
if (sb.charAt(i) == chCheck) {
sb.setCharAt(i, (char) ('0' + count));
count++;
}
}
System.out.println(sb.toString());
}
}
Please contact our admin team : 9985396677
Why are we using charAt(0)..plz explain
simple because charAt(0) return the first character in the string
Because we want to put at arr[i] in 0th index
Please explain
public static String Replace_occurances(String s,char rc) {
StringBuilder ans= new StringBuilder();
int count=1;
if(s.indexOf(rc)==-1){
System.out.println("The given character "+rc+" is not present in the String");
}else{
for(int i=0;i
🔥 Please follow us in WhatsApp channel : bit.ly/49wCWje
How to change only the second occurrence with different character?
Please Contact Our Admin Team:wa.me/+919985396677
👉 Subscribe To Our RUclips Channel: bit.ly/41IHJdj