Вы находитесь в квест-комнате по мультфильму WALL-E! Чтобы выбраться из комнаты, необходимо
выполнить такие шаги:
1. Узнайте длину строки s приведенного текста и
выведите это значение в консоль.
2. Выведите весь текст в верхнем регистре.
3. Кто-то допустил ошибку и некорректно написал имя
робота WALL-E! Замените все вхождения слова WALLE
на WALL-E.
4. Наконец, подсчитайте, сколько раз в тексте было
использовано слово Earth.
Код к заданию 1:
s = "In a distant, but not so unrealistic, future \
where mankind has abandoned earth because it has \
become covered with trash from products sold by \
the powerful multi-national Buy N Large
corporation, \
WALLE, a garbage collecting robot has been left to
\ clean up the mess. Mesmerized with trinkets of
Earth's \
history and show tunes, WALLE is alone on Earth
except \
1for a sprightly pet cockroach. One day, EVE, a
sleek \
(and dangerous) reconnaissance robot, is sent to
Earth to \
find proof that life is once again sustainable."
# Step 1
len()
# Step 2
?.upper()
# Step 3
?.replace(*, *, *)
# Step 4
?.count()
public static void main(String args[]){
java.util.Scanner in = new java.util.Scanner(System.in);
String string = in.nextLine(); char chars[] = new char[4];
chars[0] = in.nextLine().charAt(0); chars[2] = in.nextLine().charAt(0);
for(int sChar = 0; sChar<string.length(); sChar++)
if(string.charAt(sChar)==chars[0])chars[1]++;
else if(string.charAt(sChar)==chars[2])chars[3]++;
System.out.print("\n"+(chars[1]==chars[3]?chars[0]+""+chars[2]:chars[1]>chars[3]?chars[0]:chars[2]));
}
}