java 写两个方法实现判断回文数

2020-07-16 教育 73阅读
package sum;
import java.util.Scanner;
public class Ex5_3 {
public static int reverse(int num){
String b = "";
while(num!=0){
String a = Integer.toString(num%10);
num = num/10;
b += a;}
int number = Integer.parseInt(b);
return number;}
public static boolean isPalindrome(int num){
int number = reverse(num);
boolean palindrome = true;
if(num==number)
{palindrome = true;}
else
{palindrome=false;}
return palindrome;}
public static void main(String[] args) {
System.out.println("enter the number");
Scanner input= new Scanner(System.in);
int num=input.nextInt();
if((isPalindrome(num))==true)
{System.out.print("the number is palindrome.");}
else
{System.out.print("the number isnt palindrome.");}
}
}
我很认真很负责的帮你改好了 希望能采纳
声明:你问我答网所有作品(图文、音视频)均由用户自行上传分享,仅供网友学习交流。若您的权利被侵害,请联系fangmu6661024@163.com