Java 80分求助

P1307 [NOIP2011 普及组] 数字反转

SimpleJony @ 2023-05-20 20:43:39

import java.util.Scanner;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int temp = n;
        if (n<0){
            n = abs(n);
        }
        if (temp==0){
            System.out.println("0");
            System.exit(0);
        }
        String new_n = String.valueOf(n);
        StringBuilder a = new StringBuilder();
        for (int i=new_n.length()-1;i>=0;i--){
            a.append(new_n.charAt(i));
        }
        if (temp < 0) {
            a.insert(0,'-');
            if (a.charAt(1) == '0'){
                a.delete(1,2);
            }
        }
        else{
            if(a.charAt(0) == '0'){
                a.delete(0,1);
            }
        }
        String revert_n = a.toString();
        System.out.println(revert_n);
        }
    }

大佬们帮忙看看有什么问题


|