基础编程题目集 7-3 逆序的三位数 (10分)
程序员文章站
2022-03-13 12:57:59
...
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String numberString = scanner.nextLine();
String[] numberStrings = numberString.split("");
boolean hasNumber = false;
for (int i=(numberStrings.length-1); i>=0 ; i--) {
String number = numberStrings[i];
if (!hasNumber) {
if (Integer.parseInt(number) != 0) {
hasNumber = true;
System.out.print(number);
}
} else {
System.out.print(number);
}
}
scanner.close();
}
}