题解 | #数字颠倒#
数字颠倒
https://www.nowcoder.com/practice/ae809795fca34687a48b172186e3dafe
import java.util.*; // 注意类名必须为 Main, 不要有任何 package xxx 信息 public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int i1 = scanner.nextInt(); if (i1 >= 0 && i1 <= Math.pow(2, 30) - 1) { String s = Integer.toString(i1); char[] chars = s.toCharArray(); for (int i = chars.length; i > 0; i--) { System.out.print(chars[i - 1]); } } else { System.out.println("输入元素个数必须在0~(2的30次方-1)范围内"); } } }