嗨,我想知道如何获取一个名为 s 的字符串,将其拆分为两个单独的字符串,将字符串转换为整数,然后将两个整数相加。
public String add() throws IOException {
int answer;
String s = input;
String[] strings = s.split(" + ");
String string1 = strings[0].trim();
String string2 = strings[1].trim();
int x = Integer.parseInt(string1);
int y = Integer.parseInt(string2);
answer = x + y;
System.out.println(answer);
return "" + answer;
}