java
public class Test {
public static String encryptMessage(String message) {
StringBuilder encryptedMessage = new StringBuilder();
for (int i = 0; i < message.length(); i += 2) {
if (i + 1 < message.length()) {
encryptedMessage.append(message.charAt(i + 1)).append(message.charAt(i));
} else {
encryptedMessage.append(message.charAt(i));
}
}
return encryptedMessage.toString();
}
public static void main(String[] args) {
String originalMessage = "Привет, мир!";
String encrypted = encryptMessage(originalMessage);
System.out.println("Зашифрованное сообщение: " + encrypted);
}
}