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

23 种设计模式、Hash 表、数组、队列、栈、链表、树、图、堆 等
摘要:有五个学生,每个学生有3门课的成绩,从键盘输入以上数据(包括学生号,姓名,三门课成绩),计算出平均成绩,况原有的数据和计算出的平均分数存放在磁盘文件 "stud"中。 public class Example50 { public static void main(String[] args) { 阅读全文
posted @ 2017-06-10 21:42 本宫在,尔等都是妃 阅读(594) 评论(0) 推荐(0)
摘要:计算某字符串中子串出现的次数。 public class Example49 { public static void main(String[] args) { String s1 = "adcdcjncfb"; String s2 = ""; count(s1, s2); } public st 阅读全文
posted @ 2017-06-10 21:41 本宫在,尔等都是妃 阅读(177) 评论(0) 推荐(0)
摘要:某个公司采用公用电话传递数据,数据是四位的整数,在传递过程中是加密的,加密规则如下: 每位数字都加上5,然后用和除以10的余数代替该数字, 再将第一位和第四位交换,第二位和第三位交换。 public class Example48 { public static void main(String[] 阅读全文
posted @ 2017-06-10 21:40 本宫在,尔等都是妃 阅读(151) 评论(0) 推荐(0)
摘要:读取7个数(1~50)的整数值,每读取一个值,程序打印出该值个数的*。 public class Example47 { public static void main(String[] args) { int[] a = { 10, 7, 6, 15, 4, 3, 20 }; display(a) 阅读全文
posted @ 2017-06-10 21:39 本宫在,尔等都是妃 阅读(126) 评论(0) 推荐(0)
摘要:编程实现两个字符串的连接。 public class Example46 { public static void main(String[] args) { addString("hello"," world!"); } public static void addString(String s1 阅读全文
posted @ 2017-06-10 21:38 本宫在,尔等都是妃 阅读(118) 评论(0) 推荐(0)
摘要:判断一个整数能被几个9整除。 public class Example45 { public static void main(String[] args) { f(729); } public static void f(int n) { int tmp = n; int count = 0; f 阅读全文
posted @ 2017-06-09 12:36 本宫在,尔等都是妃 阅读(164) 评论(0) 推荐(0)
摘要:求0~7所能组成的奇数个数。分析:组成1位数是4个,组成2位数是7*4个,组成3位数是7*8*4个,组成4位数是7*8*8*4个…… public class Example44 { public static void main(String[] args) { f(); } public sta 阅读全文
posted @ 2017-06-09 12:35 本宫在,尔等都是妃 阅读(131) 评论(0) 推荐(0)
摘要:一个偶数总能表示为两个素数之和。 public class Example43 { public static void main(String[] args) { f(); } public static boolean fun(int a) { boolean flag = false; if 阅读全文
posted @ 2017-06-09 12:35 本宫在,尔等都是妃 阅读(132) 评论(0) 推荐(0)
摘要:809*??=800*??+9*??+1,其中??代表的两位数,8*??的结果为两位数,9*??的结果为3位数。求??代表的两位数,以及809*??后的结果。 public class Example42 { public static void main(String[] args) { f(); 阅读全文
posted @ 2017-06-09 12:34 本宫在,尔等都是妃 阅读(146) 评论(0) 推荐(0)
摘要:海滩上有若干个一堆桃子,五只猴子来分。第一只猴子把这堆桃子平均分为五份,多了一个,这只猴子把多的一个扔入海中,拿走了一份。 第二只猴子把剩下的桃子又平均分成五份,又多了一个,它同样把多的一个扔入海中,拿走了一份。第三、第四、第五只猴子都是这样做的。问海滩上原来最少有多少个桃子? public cla 阅读全文
posted @ 2017-06-09 12:33 本宫在,尔等都是妃 阅读(327) 评论(1) 推荐(0)
摘要:将几个字符串排序(按英文字母的顺序)。 public class Example40 { public static void main(String[] args) { String[] s={"math","english","java","java web","rose"}; stringSo 阅读全文
posted @ 2017-06-08 14:24 本宫在,尔等都是妃 阅读(328) 评论(0) 推荐(0)
摘要:写一个函数,求一个字符串的长度,在main函数中输入字符串,并输出其长度。 public class Example39 { public static void main(String[] args) { length("Hello World!"); } public static void l 阅读全文
posted @ 2017-06-08 14:17 本宫在,尔等都是妃 阅读(124) 评论(0) 推荐(0)
摘要:编写一个函数:输入n为偶数时,调用函数求1/2+1/4+...+1/n;当输入n为奇数时,调用函数1/1+1/3+...+1/n。 public class Example38 { public static void main(String[] args) { double d = sum(3); 阅读全文
posted @ 2017-06-08 14:17 本宫在,尔等都是妃 阅读(144) 评论(1) 推荐(0)
摘要:有n个人围成一圈,顺序排号。从第一个人开始报数(从1到3报数),凡报到3的人退出圈子,问最后留下的是原来第几号的那位。 public class Example37 { public static void main(String[] args) { f(1000); } public static 阅读全文
posted @ 2017-06-08 14:16 本宫在,尔等都是妃 阅读(178) 评论(0) 推荐(0)
摘要:有n个整数,使其前面各数顺序向后移m个位置,最后m个数变成最前面的m个数。 public class Example36 { public static void main(String[] args) { int[] m = { 18, 12, 23, 34, 95, 76, 57, 28, 9 阅读全文
posted @ 2017-06-08 14:14 本宫在,尔等都是妃 阅读(331) 评论(1) 推荐(0)
摘要:有一个数组,将其最大的元素与第一个元素交换,最小的元素与最后一个元素交换,然后输出数组。 public class Example35 { public static void main(String[] args) { int[] a = { 5, 7, 6, 1, 9, 4, 2, 3, 8 } 阅读全文
posted @ 2017-06-07 10:43 本宫在,尔等都是妃 阅读(150) 评论(0) 推荐(0)
摘要:输入3个数a,b,c,按大小顺序输出。 public class Example34 { public static void main(String[] args) { sort(5, 20, 15); } public static void sort(int a, int b, int c) 阅读全文
posted @ 2017-06-07 10:42 本宫在,尔等都是妃 阅读(162) 评论(0) 推荐(0)
摘要:打印出杨辉三角形(要求打印出10行如下图)11 11 2 11 3 3 11 4 6 4 11 5 10 10 5 1 public class Example33 { public static void main(String[] args) { yanghui(10); } public st 阅读全文
posted @ 2017-06-07 10:41 本宫在,尔等都是妃 阅读(191) 评论(0) 推荐(0)
摘要:取一个整数a从右端开始的4~7位。 public class Example32 { public static void main(String[] args) { cut(123456789); } public static void cut(long n) { String s = Long 阅读全文
posted @ 2017-06-07 10:40 本宫在,尔等都是妃 阅读(131) 评论(0) 推荐(0)
摘要:将一个数组逆序输出。 public class Example31 { public static void main(String[] args) { int[] a = { 9, 4, 6, 8, 3, 21, 16, 12 }; covertArray(a); } public static 阅读全文
posted @ 2017-06-07 10:39 本宫在,尔等都是妃 阅读(222) 评论(0) 推荐(0)