Displaying an integer reverse(整数倒置,不受位数限制)
发布时间:2020-12-13 22:13:38 所属栏目:百科 来源:网络整理
导读:问题及代码:package first;import java.util.Scanner;public class text {public static void main(String[] args) {System.out.println("请输入一个整数:");Scanner get = new Scanner(System.in);int a = get.nextInt();int sum = 0;while (a != 0) {int
问题及代码: package first; import java.util.Scanner; public class text { public static void main(String[] args) { System.out.println("请输入一个整数:"); Scanner get = new Scanner(System.in); int a = get.nextInt(); int sum = 0; while (a != 0) { int b = a % 10; sum = sum * 10 + b; a = a / 10; } System.out.println(+sum); } } 运行结果: (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |