Тэги:
#Python #Selenium_with_Python #Selenium_webdriver #Automation #Testing_tools #Selenium_tutorials #Python_tutorials #Manual_testing #SDET #Java #selenium_with_java #big_data #hadoop #web_services #postman #soapui #rest_assured #SQL #Programming #Software_Testing_material #selenium_videos #python_videos #automation_vidios #jira #jmeter #performance_testing #functional_testing #QA #QC #Agile_testing #SDLC #Automation_Step_by_Step #restapi #Count_Occurrences_of_a_Character_in_a_StringКомментарии:
Superb easy to understand sir...thanks a lot for helping us.
Ответитьimport java.util.Arrays;
class OccrenceOfInputArray {
public static void main(String[] args) {
int arr[] = {1, 1, 2, 2, 3, 4, 5, 6, 8, 9};
int len = arr.length;
System.out.println("Total length: " + len);
String arrString = Arrays.toString(arr);
// Replace '2' with an empty string and get the length
int totalCount = len - arrString.replace("2", "").length();
System.out.println("Total count of 2: " + totalCount);
}
}
sir, while im running this program after removing the 2 we got the output is 8, but here output is getting is: -18..........please clarify this doubt sir
not a good approach
Ответитьimport java.util.HashMap;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
System.out.print("\nEnter a statement: ");
Scanner scan = new Scanner(System.in);
String statement = scan.nextLine();
scan.close();
String[] words = statement.split("\\s+");
HashMap<String, Integer> wordHashMap = new HashMap<>();
HashMap<Character, Integer> letterHashMap = new HashMap<>();
for (int i = 0; i < statement.length(); i++){
char currentChar = statement.charAt(i);
if (letterHashMap.containsKey(currentChar)){
letterHashMap.put(currentChar, letterHashMap.get(currentChar) + 1);
} else {
letterHashMap.put(currentChar, 1);
}
}
for (Character letter : letterHashMap.keySet()){
int count = letterHashMap.get(letter);
System.out.println("Letter: " + letter + " appears " + count + " times.");
}
for (String word : words){
if (wordHashMap.containsKey(word)){
wordHashMap.put(word, wordHashMap.get(word) + 1);
} else {
wordHashMap.put(word, 1);
}
}
for (String item : wordHashMap.keySet()){
int count = wordHashMap.get(item);
System.out.println("Word: " + item + " appears: " + count + " times.");
}
}
}
I think string.chatAT(i) ==letter and count ++ will do the job right
ОтветитьSir Your explanation is very nice and am very thankful to you sir
ОтветитьSir we can use Hashmap that would be more efficient
ОтветитьI was very scary to make understand coding earlier. But once I started watching your videos, my thought process changed.
I am very comfortable to understand your logics, I feel like "OH CODING IS SUCH SIMPLE" 😄🤣
Great Thank you Pavan sir..🤝🤝🙏🙏
hi sir can we use this method is scanner sirif yes can u tell me how to use it
ОтветитьAmazing video sir ! You code in such simple way and explain it so well that any basic /intermediate base person can fully grasp the concept and learn coding.
ОтветитьThank You Sir... You Make My Logic Building Strong... Simple And Up to The Mark Explanation...😇🙏
Ответитьsir please make more interview programs
ОтветитьSir make program video of duplicate characters in a string
Ответитьwhy writing this much complex...i dont know............
we can write in this way too
String s="yash is a good boy ";
char comp='a';
int flag=0;
for(int i=0;i<s.length();i++){
if(s.charAt(i)==comp){
flag++;
}
}
System.out.println(flag);
This question asked me today
ОтветитьSir what about when there are same letter with upper and lower case.
ОтветитьNot working giving output as zero
ОтветитьExcellent explanation
Ответитьthis is easiest program i have seen ..thanks sir
Ответитьimpressive.
Ответитьif we get string from the user then how to get max occuring character
Ответитьcorrupted
ОтветитьThis for known statement.. Then what is code for when we use scanner Class
ОтветитьSir y u removing a es
ОтветитьWhat about no case sensitive
ОтветитьGreat explain....🙌🙌
ОтветитьThis is working but does not count uppercase characters if we are pass lowercase or vice versa
Ответитьwe simply sovle the problem like
int count =s.replaceAll("[^a]","").length();
very easy sir.thank u. sir can u please make programm for prime no. from array ..please sir .
ОтветитьLove your videos and commenting for better reach. You have a great voice btw.
ОтветитьThankyou sir for this video...
ОтветитьThis was asked in my interview
ОтветитьTell for all character occurences. For all occurences it will become a very exhausting code
Ответитьcan u tell me how to check for all the character occurence
Ответитьthis method is also easy check it guys'
String str="java programming is very easy";
int count=0;
for(int i=0;i<str.length();i++) {
if(str.charAt(i)=='a') {
count++;
}
}
System.out.println("number of occurances letter a :"+count);
try this one also easy and thank u sir for these videos
Can i get this in loop.. if yes can u comment the statement..
ОтветитьNice explanation however I am bit confused, as we count the spaces as well in index., So when we are replacing a with space, the space would still be counted. so not sure how did it work. Could you please explain the logic for that. Thank you
ОтветитьThanks for easy explanation and can we do the same program without "replace" method? please explain the approach as well
ОтветитьBonne vidéo
ОтветитьNice explanation
Ответить