社区讨论
又错了
P1001A+B Problem参与者 3已保存回复 4
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 3 条
- 当前快照
- 1 份
- 快照标识符
- @m5679010
- 此快照首次捕获于
- 2024/12/27 11:34 去年
- 此快照最后确认于
- 2024/12/27 19:12 去年
JAVA
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);//扫描系统输入
String numSpaceNum = scanner.nextLine();
String[] two = numSpaceNum.split(" ");
String numLeft = two[0], numRight = two[1];
int nLeft = stringToInt(numLeft), nRight = stringToInt(numRight);//想再次声明为不一样的类型
System.out.println(nLeft + nRight);
}
static int stringToInt(String Int) {
int result = 0, mul = 10;
boolean isMinus = false;
if (Int.charAt(0) == '-') {
Int = Int.substring(1);
isMinus = true;
}
char[] per = Int.toCharArray();
per = reverse(per);
for (char c : per) {
result = (c - '0') * mul;
mul *= 10;
}
if (isMinus)
result *= -1;
return result;
}
static char[] reverse(char[] old) {
char[] New = new char[old.length];
for (int i = New.length - 1, i2 = 0; i >= 0 && i2 < old.length; i--, i2++) {
New[i] = old[i2];
}
return New;
}
}
回复
共 4 条回复,欢迎继续交流。
正在加载回复...