《java回文数代码》由会员分享,可在线阅读,更多相关《java回文数代码(2页珍藏版)》请在金锄头文库上搜索。
1、importimport javax.swing.JOptionPane;publicpublic classclass Numberpublicpublic staticstatic voidvoid main(String args) intint number = 0,d5,d4,d3,d2,d1; String str = JOptionPane.showInputDialog(输入一个1至99999之间的数); number = Integer.parseInt(str);ifif(0number&number0)/判断number是5位数的条件 System. out.printl
2、n(number + 是5位数);ifif(d5=d1&d4=d2) System.out.println(number + 是回文数);elseelse System.out.println(number + 不是回文数); elseelse ifif(d40)/判断number是4位数的条件 System. out.println(number + 是4位数);ifif(d4=d1&d2=d3)/判断number是回文数的条件代码 System. out.println(number + 是回文数); elseelse System. out.println(number +不是回文数);
3、 elseelse ifif(d30)/判断number是3位数的条件 System. out.println(number + 是3位数);ifif(d3=d1)/判断number是回文数的条件 System.out.println(number + 是回文数); elseelse System. out.println(number +不是回文数); elseelse ifif(d2 != 0) System. out.println(number + 是2位数);ifif(d1 = d2) System. out.println(number +是回文数); elseelse System. out.println(number +不是回文数); elseelse ifif(d1 = 0 ) System. out.println(number + 是1位数); System. out.println(number +是回文数); elseelse System.out.printf(n= %d不在1至99999之间,number);