packagelesson.l2_for;//打印//*//**//***//****//*****publicclassForDemo9{publicstaticvoidmain(String[] args){for(int i =1; i <=5; i++){for(int j =1; j <= i; j++){System.out.print("*");}System.out.println();}}}
代码2-1
packagelesson.l2_for;//打印//****//***//**//*publicclassForDemo10{publicstaticvoidmain(String[] args){for(int i =4; i >=1; i--){for(int j = i; j >=1; j--){System.out.print("*");}System.out.println();}}}
代码2-2
packagelesson.l2_for;//打印//****//***//**//*publicclassForDemo10_2{publicstaticvoidmain(String[] args){for(int i =1; i <=4; i++){for(int j =1; j <=5-i ; j++){System.out.print("*");}System.out.println();}}}
代码3
packagelesson.l2_for;//打印//*//**//***//****//*****//****//***//**//*publicclassForDemo11{publicstaticvoidmain(String[] args){for(int i =1; i <=5; i++){for(int j =1; j <= i; j++){System.out.print("*");}System.out.println();}for(int i =1; i <=4; i++){for(int k =1; k <=5- i; k++){System.out.print("*");}System.out.println();}}}
代码4
packagelesson.l2_for;//打印棱形publicclassForDemo12{publicstaticvoidmain(String[] args){for(int i =1; i <=5; i++){for(int j =1; j <=6-i; j++){System.out.print(" ");}for(int k =1; k <= i; k++){System.out.print(" *");}System.out.println();}for(int i =1; i <=4; i++){for(int j =1; j <=i+1; j++){System.out.print(" ");}//for (int j = i; j <=4; j++) {for(int j =1; j <=5-i; j++){System.out.print(" *");}System.out.println();}}}
注意
二分查找要求原数组为有序序列,从小到大
递归解法 public class problem9 {public static void main(String[] args) {int[] arr {1,2,3,4,6,7};int left 0;int right arr.length - 1;int value 2;System.out.println(Arrays.toString(arr));int index …
题目
移动盘子,每一次只能移动一个,小盘子在大盘子上。
打印1 from A to B过程 注意
1)盘子编号的变化和辅助柱子的变化
2)当盘子编号为1时,结束递归,此时移动结束
代码
package p2;/*** Illustratio…
题目 代码1
public class YangHuiTriangle {public static void main(String[] args) {print(10);}public static void print(int num) {int[][] arr new int[num][];for (int i 0; i < num; i) {
// 第一行有 1 个元素, 第 n 行有 n 个元素arr[i] new int[i…