You are on page 1of 2

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;

public boolean check(String word){


char[] arr = word.toCharArray();
for(char c : arr){
if(Character.isDigit(c);
int number = Interger.parseInt(c+""));
if (number % 2 != 0){
return true;
}
return false
}
}

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

You might also like