随笔分类 -  设计模式、算法

23 种设计模式、Hash 表、数组、队列、栈、链表、树、图、堆 等
摘要:一球从100米高度自由落下,每次落地后反跳回原高度的一半;再落下……求它在第10次落地时,共经过多少米?第10次反弹多高? public class Example10 { public static void main(String[] args) { height(); } public sta 阅读全文
posted @ 2017-06-01 11:38 本宫在,尔等都是妃 阅读(486) 评论(2) 推荐(0)
摘要:一个数如果恰好等于它的因子之和,这个数就称为"完数"。例如6=1+2+3。编程找出1000以内的所有完数。 public class Example09 { public static void main(String[] args) { number(); } public static void 阅读全文
posted @ 2017-06-01 11:37 本宫在,尔等都是妃 阅读(226) 评论(0) 推荐(0)
摘要:求s=a+aa+aaa+aaaa+aa...a的值,其中a是一个数字。例如2+22+222+2222+22222(此时共有5个数相加),几个数相加由键盘控制。 public class Example08 { public static void main(String[] args) { sum( 阅读全文
posted @ 2017-06-01 11:36 本宫在,尔等都是妃 阅读(174) 评论(0) 推荐(0)
摘要:输入一行字符,分别统计出其中英文字母、空格、数字和其它字符的个数。 public class Example07 { public static void main(String[] args) { String s = "Hello World! BeiJing AoYun 2008。"; num 阅读全文
posted @ 2017-06-01 11:35 本宫在,尔等都是妃 阅读(184) 评论(0) 推荐(0)
摘要:输入两个正整数m和n,求其最大公约数和最小公倍数。 public class Example06 { public static void main(String[] args) { int a = 1; int b = 10; int max = f(a, b); int min = a * b 阅读全文
posted @ 2017-06-01 11:34 本宫在,尔等都是妃 阅读(236) 评论(1) 推荐(0)
摘要:利用条件运算符的嵌套来完成此题:学习成绩>=90分的同学用A表示,60-89分之间的用B表示,60分以下的用C表示。 public class Example05 { public static void main(String[] args) { score(90); } public stati 阅读全文
posted @ 2017-05-31 15:50 本宫在,尔等都是妃 阅读(151) 评论(0) 推荐(0)
摘要:将一个正整数分解质因数。例如:输入90,打印出90=2*3*3*5。 public class Example04 { public static void main(String[] args) { f(100); } public static void f(int n) { int k = 2 阅读全文
posted @ 2017-05-31 15:47 本宫在,尔等都是妃 阅读(197) 评论(0) 推荐(0)
摘要:打印出所有的"水仙花数",所谓"水仙花数"是指一个三位数,其各位数字立方和等于该数本身。例如:153是一个"水仙花数",因为153=1的三次方+5的三次方+3的三次方。 public class Example03 { public static void main(String[] args) { 阅读全文
posted @ 2017-05-31 15:38 本宫在,尔等都是妃 阅读(287) 评论(0) 推荐(0)
摘要:判断101-200之间有多少个素数,并输出所有素数。 public class Example02 { public static void main(String[] args) { prime(); } public static void prime() { int count = 0; fo 阅读全文
posted @ 2017-05-31 15:36 本宫在,尔等都是妃 阅读(227) 评论(0) 推荐(0)
摘要:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第四个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少? public class Example01 { public static void main(String[] args) { int a = 8; int su 阅读全文
posted @ 2017-05-31 15:34 本宫在,尔等都是妃 阅读(323) 评论(0) 推荐(0)