又错了
  • 板块P1001 A+B Problem
  • 楼主QAQ5
  • 当前回复3
  • 已保存回复4
  • 发布时间2024/12/27 11:33
  • 上次更新2024/12/27 19:12:46
查看原帖
又错了
749028
QAQ5楼主2024/12/27 11:33
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;
    }
}
2024/12/27 11:33
加载中...