Java:利用字符数组将整数反转


package com.zbj.demo;

import org.junit.Test;

public class NumReverse {
	int a = 1234;
	int b = -6379;

	@Test
	public void numreverse() {
		char[] chars = ("" + b).toCharArray();
		int i = 0, j = chars.length - 1;
		if (chars[0] == '-') {
			i = 1;

		}

		for (; i < j; i++, j--) {
			char temp = chars[i];
			chars[i] = chars[j];
			chars[j] = temp;
		}
		// System.out.println(new String(chars));
		int parseInt = Integer.parseInt(new String(chars));
		System.out.println(parseInt);
	}
}

Java:利用字符数组将整数反转