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:利用字符数组将整数反转

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-25
  • 2022-12-23
  • 2022-12-23
  • 2022-01-03
  • 2022-12-23
  • 2021-05-17
猜你喜欢
  • 2022-12-23
  • 2021-06-14
  • 2021-09-22
  • 2021-12-10
  • 2021-12-19
  • 2022-12-23
  • 2021-11-19
相关资源
相似解决方案