- Get link
- X
- Other Apps
YouTube Link : Click Here
package Accenture_Coding_Question;
public class Win_or_Fail {
public static void main(String[] args) {
int a[] = {1,0,1,1,1,1,0,1,0,1,1,1};
int count = 0;
int max = Integer.MIN_VALUE;
for (int i = 0; i < a.length; i++) {
if(a[i] == 1){
count++;
max = Math.max(max,count);
}
else{
count = 0;
}
}
System.out.println(max);
}
}
package Accenture_Coding_Question;
import java.util.HashMap;
import java.util.Map;
public class Count_Vowel_In_String {
public static void main(String[] args) {
String s = "GOD IS GREAT"; // change into lower or upper if you need
HashMap<Character,Integer> map = new HashMap<>();
for (char ch : s.toCharArray()){
if(ch == 'A' || ch == 'E' || ch == 'I' || ch == 'O' || ch == 'U'){
map.put(ch,map.getOrDefault(ch,0)+1);
}
}
int max = Integer.MIN_VALUE;
for(char vowel : map.keySet()){
System.out.println(vowel + " : "+map.get(vowel));
max = Math.max(max,map.get(vowel));
}
String foundKey = null;
for (Map.Entry<Character, Integer> entry : map.entrySet()) {
if (entry.getValue() == max) {
foundKey = String.valueOf(entry.getKey());
break; // Stop once we find the first key with the value
}
}
System.out.println("Answer is :: "+ foundKey + " : " + max);
}
}
Comments
Post a Comment