题解 | #按照格式输入并交换输出#
按照格式输入并交换输出
http://www.nowcoder.com/practice/95eb723a3e854376a7eb6d116cc7d875
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String[] s = sc.nextLine().split(",");
// 将满足条件的字符串 1 换成 2, 2 换成 1
for (int i = 0; i < s.length; i++) {
if (s[i].indexOf("1") > 0) {
s[i] = s[i].replace("1", "2");
} else {
s[i] = s[i].replace("2", "1");
}
}
// 将数组转换成字符串
String result = String.join(",", s);
System.out.println(result);
}
}