回文数的JAVA程序
2019獨角獸企業重金招聘Python工程師標準>>>
這是包括字符的回文數
import java.util.Scanner;
import javax.swing.JOptionPane;
public class HuiShu {
public static void main(String args[]) {
String s;
while (true) {
System.out.println("請輸入字符串");
Scanner reader = new Scanner(System.in);
s = reader.nextLine();
try{
Integer.parseInt(s);
break;
}catch(Exception e){
JOptionPane.showMessageDialog(null, "輸入的不是一個數,請重新輸入");
}
}
char a[] = s.toCharArray();
char b[] = new char[a.length];
int i;
for (i = 0; i < a.length; i++) {
b[a.length - i - 1] = a[i];
}
String x = new String(a);
String y = new String(b);
if (x.equals(y))
System.out.println("回文數");
else
System.out.println("非回文數");
}
}
轉載于:https://my.oschina.net/pracy87/blog/2992
總結
以上是生活随笔為你收集整理的回文数的JAVA程序的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: F5 network
- 下一篇: 竞选三好学生需做ppt吗