java回文数 代码修改

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("你输入的不是回文数");
}
}

第1个回答  2008-10-24
package JOptionPane;

import javax.swing.JOptionPane;

/**
* @author songml
*
*/
public class huiwen1 {
/**
* @param args
*/
public static void main(String[] args) {
//bFlg为true的时候,显示对话框
//bFlg为false的时候,不显示对话框,程序结束
boolean bFlg = true;
while (bFlg) {
String inputValue = JOptionPane.showInputDialog("请输入一个五位整数");
//什么都没有输入的时候的处理
if ("".equals(inputValue) ){inputValue ="0";}
//点击"取消"时候的处理
if (null == inputValue ) {bFlg = false;continue;}
//五位数判断
if (inputValue.length() !=5) {
JOptionPane.showMessageDialog(null, "请输入一个五位数");
//跳出本次(上面的那个)while,目的是不运行下面的回文数判断
continue;
}
long inputValueLong = Long.parseLong(inputValue);
long temp = inputValueLong;
long reverseLong = 0L;
//回文数判断
while (inputValueLong != 0) {
reverseLong = reverseLong * 10 + inputValueLong % 10;
inputValueLong = inputValueLong / 10;
}
if (reverseLong == temp) {
JOptionPane.showMessageDialog(null, "你输入的是回文数");
bFlg =false;
} else {
JOptionPane.showMessageDialog(null, "你输入的不是回文数");
}
}

System.exit(0);
}
}
第2个回答  2008-10-24
随便写了个...

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("你输入的不是回文数");
}
}
}本回答被提问者采纳
第3个回答  2008-10-24
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(buf.reverse().toString()))
System.out.println("你输入的是回文数");
else
System.out.println("你输入的不是回文数");
}
}
第4个回答  2008-10-24
package com.test;
import javax.swing.JOptionPane;
import java.lang.Math;

public class Test
{
public static void main(String [] args)
{

long inputValueLong;
String inputValue = null ;

inputValue=JOptionPane.showInputDialog("请输入一个5位整数");
inputValueLong = Long.parseLong(inputValue);//存放该整数

long temp = inputValueLong;
long reverseLong =0L;
long index=0L;
for(int i=5;i>=1;i--){
index=inputValueLong%10;
reverseLong =(long)(reverseLong+index*Math.pow(10,i-1));
inputValueLong = inputValueLong/10;
System.out.println(reverseLong);
}

if(reverseLong == temp)
System.out.println("你输入的是回文数");
else
System.out.println("你输入的不是回文数");
}
}
第5个回答  2008-10-24
起码的逻辑都不对.
相似回答