Professional Documents
Culture Documents
B3
B3
f2
int max = list.get(0).getPrice();
for (int i = 1; i < list.size();i++){
if(list.get(i).getPrice()>max){
max = list.get(i).getPrice();
}
}
int count = 0;
int count_De = 2;
for(int i = 0;i<list.size();i++){
if(list.get(i).getPrice() == max){
count++;
}
if(count == count_De){
list.remove(list.get(i));
break;
}
}
f3
Collection.sort(list, (c1,c2) -> c1.getOwner().charAt(1) -
c2.getOwner().charAt(1)));
B4
f1(dem so luong tu)
String[] words = string.split("\\s+");
int count = 0;
for (String word : words){
if(Dieu kien: check(word){
count++;
}
}
return count;
f2:
public static boolean checkStringPalindrome(String s) {
StringBuilder sb = new StringBuilder(s);
return s.equals(sb.reverse().toString());
}
String rs = "";
String[] words = string.split("\\s+");
int count = 0;
for (String word : words){
if(checkStringPalindrome(word) && count == 0){
word = "XX";
count++;
}
rs = word + " ";
}
return rs.trim();