一个5位数,判断它是不是回文数。即12321是回文数,个位与万位相同,十位与千位相同。 public class Example25 { public static void main(String[] args) { f2(123454321); }//方法一 public static void Read More
posted @ 2017-06-05 12:04 本宫在,尔等都是妃 Views(153) Comments(0) Diggs(0) Edit
有5个人坐在一起,问第5个人多少岁,他说比第4个人大2岁。问第4个人岁数,他说比第3个人大2岁。 问第三个人,他说比第2人大两岁。问第2个人, 说比第一个人大两岁。最后问第一个人,他说是10岁。 请问第五个人多大? public class Example24{ public static void Read More
posted @ 2017-06-05 12:02 本宫在,尔等都是妃 Views(145) Comments(0) Diggs(0) Edit
给一个不多于5位的正整数,要求:①求它是几位数;②逆序打印出各位数字。 public class Example23 { public static void main(String[] args) { f(123789); } public static void f(long l) { Stri Read More
posted @ 2017-06-05 12:02 本宫在,尔等都是妃 Views(120) Comments(0) Diggs(0) Edit
利用递归方法求5!。 public class Example22 { public static void main(String[] args) { int n = 5; long s = sum(n); System.out.println(n + "!= " + s); } public s Read More
posted @ 2017-06-05 12:01 本宫在,尔等都是妃 Views(163) Comments(0) Diggs(0) Edit
求1+2!+3!+...+20!的和。 public class Example21 { public static void main(String[] args) { sum(20); } public static void sum(int n) { long sum = 0; long fa Read More
posted @ 2017-06-05 11:59 本宫在,尔等都是妃 Views(261) Comments(0) Diggs(0) Edit