兰聪


私信TA

用户名:lc2024228712

访问量:2756

签 名:

等  级
排  名 143
经  验 7158
参赛次数 8
文章发表 18
年  龄 0
在职情况 学生
学  校 鄂州职业大学
专  业

  自我简介:

TA的其他文章

解题思路:


使用StringBuilder的reverse()方法反转字符串


参考代码:

import java.util.Scanner;

public class 反置数01 {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();

		String str1 = n + ""; // int类型转成字符串
		String str2 = m + "";
		
		n = Integer.parseInt(new StringBuilder(str1).reverse().toString()); // 调用reverse()方法反转字符串,然后赋值给n
		m = Integer.parseInt(new StringBuilder(str2).reverse().toString());
		
		String str3 = (n + m) + "";
		
		int sum = Integer.parseInt(new StringBuilder(str3).reverse().toString());
		System.out.println(sum);
	}

}


 

0.0分

5 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答

代码解释器

  评论区