用StringBuilder的reverse方法,和Integer的parseInt方法:
import java.util.*; public class Main { public static void main(String[] args) throws Exception{ Scanner sc = new Scanner(System.in); int x = sc.nextInt(), y = sc.nextInt(); StringBuilder s1 = new StringBuilder(Integer.toString(x)).reverse(); StringBuilder s2 = new StringBuilder(Integer.toString(y)).reverse(); int r = Integer.parseInt(s1.toString()) + Integer.parseInt(s2.toString()); StringBuilder ans = new StringBuilder(Integer.toString(r)).reverse(); System.out.println(Integer.parseInt(ans.toString())); } }