Java Program To Replace Character With It's Occurrence | Java | Ashok IT
ฝัง
- เผยแพร่เมื่อ 14 ต.ค. 2024
- ✍️✍️ Register Here For Online Training : bit.ly/4dBYJbX
** For Online Training ► Call: +91-6301921083
Subscribe to our channel and hit the bell 🔔🔔🔔 icon to get video updates.
💡 Visit Our Website
For Online Training: www.ashokit.in
💡 About Ashok IT :
Ashok IT is the No.1 quality training institute in India for the candidates who want to build their future in Information Technology. We are into online training, class room training, corporate training and one to one training with more passion and dedication. Ashok IT aims in providing best quality realtime oriented trainings on C, C++, Java, Spring , Spring REST, Spring Cloud, Microservices, Python, DJango, .Net, Angular, React JS, Salesforce, , Testing, Android, Docker, Kubernates, Manual Testing, Selenium and Digital Marketing.
-----------------------------------------------------------------------------------
💡 Our Online Training Features
🎈 Training with Real-time Working Professionals
🎈 Industry Matching use cases
🎈 Live Coding
🎈 Real-time Environment
🎈 Class Notes
🎈 Doubts Clarifications in Each Session
-----------------------------------------------------------------------------------
💡 Contact details:
☎ WhatsApp Number: +91-6301921083
► Website : www.ashokit.in
► Join with us in Telegram : bit.ly/3iP2KyA
► Like us in Facebook : bit.ly/3dw6R0A
► Follow us in Instagram : bit.ly/3jzEKl8
► Follow us in Twitter : bit.ly/2SDqdK4
🔥 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
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
Nice. Kindly give data structure video also
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 ?
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
What would happen if we just did it as arr[i] = String.valueOf(cnt); ?
please contact our admin team : +91 9985396677
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
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 TH-cam Channel: bit.ly/41IHJdj