package com.example.practice;
import java.util.Scanner;
//将输入的数字反向输出
public class Test2 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入一串数字:");
if (scanner.hasNextInt()) {
int num = scanner.nextInt();
StringBuilder builder = new StringBuilder();
StringBuilder opposite = null;
while (num != 0) { //"%"表示取余数
int res = num % 10; //取出最后一位
num = num / 10;
opposite = builder.append(res);
}
System.out.println(opposite);
} else {
System.out.println("输入有误");
}
}
}
标签:输出,scanner,opposite,StringBuilder,System,num,反向,输入,out
From: https://www.cnblogs.com/faith007/p/17211734.html