You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
54 lines
1.3 KiB
54 lines
1.3 KiB
package leo.class07_11;
|
|
|
|
/**
|
|
* @author Leo
|
|
* @ClassName PaperFolding
|
|
* @DATE 2020/12/10 9:43 上午
|
|
* @Description 打印一张纸条对着n次后的折痕
|
|
*/
|
|
public class PaperFolding {
|
|
|
|
|
|
public static void printAllFolds(int n) {
|
|
if (n < 0) {
|
|
return;
|
|
}
|
|
processPrint(1, n, true);
|
|
System.out.println();
|
|
|
|
}
|
|
|
|
public static void processPrint(int i, int n, boolean boo) {
|
|
if (i > n) {
|
|
return;
|
|
}
|
|
processPrint(i + 1, n, true);
|
|
System.out.print(boo ? "凹 " : "凸 ");
|
|
processPrint(i + 1, n, false);
|
|
}
|
|
|
|
public static void printAllFolds1(int n) {
|
|
if (n < 0) {
|
|
return;
|
|
}
|
|
processPrint1(1, n, true);
|
|
System.out.println();
|
|
}
|
|
|
|
public static void processPrint1(int i, int n, boolean du) {
|
|
if (i > n) {
|
|
return;
|
|
}
|
|
processPrint1(i + 1, n, true);
|
|
System.out.print(du ? "凹 " : "凸 ");
|
|
processPrint1(i + 1, n, false);
|
|
}
|
|
|
|
public static void main(String[] args){
|
|
//凹 凹 凸 凹 凹 凸 凸 凹 凹 凹 凸 凸 凹 凸 凸
|
|
//凹 凹 凸 凹 凹 凸 凸 凹 凹 凹 凸 凸 凹 凸 凸
|
|
//凹 凹 凸 凹 凹 凸 凸 凹 凹 凹 凸 凸 凹 凸 凸
|
|
printAllFolds1(4);
|
|
}
|
|
}
|