50分Java求助,我感觉对的很呐qwq

P1307 [NOIP2011 普及组] 数字反转

chengyan @ 2023-09-09 20:32:46


import java.util.Scanner;

public class NumberInversion {
    public static void main(String[] args) {
        Scanner myScanner=new Scanner(System.in);
        long a=myScanner.nextLong();
        a=(long)Math.sqrt((double)a*a);
        long reservedNumber=0l;
        long temp=a;

        while(true){
            reservedNumber=reservedNumber*10+a%10;
            a=a/10;
            if(a==0){
                break;
            }
        }

        if(temp<0){
            System.out.println("-"+reservedNumber);
        }else if(temp>0){
            System.out.println(reservedNumber);
        }else if(temp==0){
            System.out.println(0);
        }
    }
}

|