package com.fqs.test; import java.util.Scanner; import static jdk.nashorn.internal.objects.ArrayBufferView.length; public class hello { public static void main(String[] args) { //如果是回文数 打印true 否则打印false Scanner sc=new Scanner(System.in); System.out.print("请输入一个数字比如12345"); int num = sc.nextInt(); int bi_num=num;//将值保存到bi_num中,防止之后被改变 int result=0; //拿num除以10 如果大于0继续除,小于0不再除 while (num>0){ int x=num%10;//比如12345对10求余得到5 result=result*10+x;//结果0*10+5=5 num/=10;//输入的值除以10 等于1234.5 大于0所以继续 } System.out.print("result:"+result+"\n"); System.out.print("bi_num:"+bi_num+"\n"); if(bi_num == result){ System.out.print("true"); } else{ System.out.print("false"); } } }
标签:10,System,bi,while,num,result,out From: https://www.cnblogs.com/haha1988/p/17452908.html