Java Program To Replace Character With It's Occurrence | Java | Ashok IT

preview_player
Показать описание

** For Online Training ► Call: +91-6301921083

Subscribe to our channel and hit the bell 🔔🔔🔔 icon to get video updates.

💡 Visit Our Website

💡 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
Рекомендации по теме
Комментарии
Автор

for(int i = 0 ; i<temp.length;i++) {
if(temp[i]==replace) {
temp[i]=(char) (count+49);
count++;

}
this can also be done since ascii of 1 is 49

moumajhi
Автор

Nice. Kindly give data structure video also

lokeshkumar
Автор

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

YashSingh-xsyj
Автор

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 ?

my_love_sanatan
Автор

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);

sainath
Автор

What would happen if we just did it as arr[i] = String.valueOf(cnt); ?

beastcombatanalysing
Автор

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

ajayghode
Автор

package StringQuestions;

public class {

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++;
}
}


}
}

YashSingh-xsyj
Автор

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<s.length();i++){
char ch=s.charAt(i);
if(ch==rc){
ans.append(count);
count++;
}else{
ans.append(ch);
}
}
}
return ans.toString();
}

umadevialamkonda
Автор

Why are we using charAt(0)..plz explain

frustrated_majdoor
Автор

How to change only the second occurrence with different character?

vigneshr