按题目分类要求,使用递归算法:
import java.util.Scanner; public class Main{ public static void main(String[] args){ Scanner sc = new Scanner(System.in); int n = sc.nextInt(); reverse(n); } public static void reverse(int n){ if(n > 0){ System.out.print(n%10); reverse(n/10); } } }