题解 | #数字颠倒#
数字颠倒
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 i = scanner.nextInt(); String s = String.valueOf(i); String[] split = s.split("");//拆分输入整数字符串 HashMap<Integer, String> hash = new HashMap<>(); for (int j = split.length-1; j >=0; j--) { String s1 = split[j];//将数组依据下标从后向前放入map hash.put(j,s1); } StringBuilder sb = new StringBuilder(); for (int j = split.length-1; j >=0; j--) { String s1 = hash.get(j);//从map中从后向前取出value后进行stringbuider拼接字符串 sb=sb.append(s1); } System.out.print(sb); } }