java回文数 代码修改

来源:百度知道 编辑:UC知道 时间:2024/09/27 08:13:19
import javax.swing.JOptionPane;
public class huiwen1
{
public static void main(String [] args)
{

long inputValueLong;
String inputValue = null ;

do{
inputValue=JOptionPane.showInputDialog("请输入一个5位整数");
inputValueLong = Long.parseLong(inputValue);//存放该整数
}
long inputValueLong = Long.parseLong(inputValue);
long temp = inputValueLong;
long reverseLong = 0L;
while(inputValue.length()!=5);

{
reverseLong = reverseLong*10+inputValueLong%10;
inputValueLong = inputValueLong/10;
}
if(reverseLong == temp)
System.out.println("你输入的是回文数");
else
System.out.println("你输入的不是回文数");
}
}

随便写了个...

import javax.swing.JOptionPane;

public class Reverse {

public static String input(){
String inputValue=JOptionPane.showInputDialog("请输入一个5位整数");
return inputValue;
}

public static void main(String [] args)
{
String string=input();
if(string.length()!=5){
System.out.println("非法!");
return;
}else{
char[] temp=string.toCharArray();
if(temp[0]==temp[4]&&temp[1]==temp[3])
System.out.println("你输入的是回文数");
else
System.out.println("你输入的不是回文数");
}
}
}

import javax.swing.JOptionPane;

public class huiwen1 {
public static void main(String [] args){
StringBuffer buf = new StringBuffer();
String inputValue = null ;
inputValue = JOptionPane.showInputDialog("请输入一个5位整数");
buf.append(inputValue);
if(inputValue.equalsIgnoreCase