力扣(LeetCode) 整数反转

来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/reverse-integer
 

题目:

给出一个 32 位的有符号整数,你需要将这个整数中每位上的数字进行反转。

示例 1:

输入: 123
输出: 321


 示例 2:

输入: -123
输出: -321


示例 3:

输入: 120
输出: 21


import java.util.Scanner;

public class Main{
	private static boolean zf;

	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		if(a<0) {
			a=Math.abs(a);
			zf=true;
		}
			
		String str=String.valueOf(a);
		char[] b=str.toCharArray();
		if(b.length%2==0) {
			for(int i=0;i

 

 

 

 

你可能感兴趣的:(力扣(LeetCode) 整数反转)