我下面的代码应该接受用户的整数,然后以相反的顺序打印他们输入的任何整数。我没有收到任何错误,但是当我运行该程序时,整数并未反向打印。有人可以帮我找出原因吗?
import java.util.*;
public class ReverseDigits {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String response;
System.out.println("Please enter a whole number.");
response = sc.next();
reverseDigit(response);
}
public static void reverseDigit(String digit) {
ArrayList al = new ArrayList();
al.add(digit);
Collections.reverse(al);
System.out.println("Your number in reverse order is: " + al);
}
}
Run Code Online (Sandbox Code Playgroud)