程序:1
package afterfeb13;
public class patternfornumber {
public static void main(string[] args) {
// number1();
// number2();
// number3();
// number4();
// number5();
// number6();
// number7();
// number8();
number9();
}
private static void number9() {
for (int row = 1; row <= 9; row++) {
for (int col = 1; col <= 9; col++) {
if (row == 1 && (col <= 7 && col >= 3) || row == 5 && (col <= 7 && col >= 3)
|| row == 9 && (col <= 7 && col >= 3) || col == 3 && row <= 5 || col == 7) {
system.out.print("* ");
}
else {
system.out.print(" ");
}
}
system.out.println();
}
}
private static void number8() {
for (int row = 1; row <= 9; row++) {
for (int col = 1; col <= 9; col++) {
if (row == 1 && (col <= 7 && col >= 3) || row == 5 && (col <= 7 && col >= 3)
|| row == 9 && (col <= 7 && col >= 3) || col == 3 || col == 7) {
system.out.print("* ");
}
else {
system.out.print(" ");
}
}
system.out.println();
}
}
private static void number7() {
for (int row = 1; row <= 9; row++) {
for (int col = 1; col <= 9; col++) {
if (row == 1 && col > 3 || row + col == 10) {
system.out.print("* ");
}
else {
system.out.print(" ");
}
}
system.out.println();
}
}
private static void number6() {
for (int row = 1; row <= 9; row++) {
for (int col = 1; col <= 9; col++) {
if (row == 1 && (col <= 7 && col >= 3) || row == 5 && (col <= 7 && col >= 3)
|| row == 9 && (col <= 7 && col >= 3) || col == 3 || col == 7 && row >= 5) {
system.out.print("* ");
}
else {
system.out.print(" ");
}
}
system.out.println();
}
}
private static void number5() {
for (int row = 1; row <= 9; row++) {
for (int col = 1; col <= 9; col++) {
if (row == 1 && (col <= 7 && col >= 3) || row == 5 && (col <= 7 && col >= 3)
|| row == 9 && (col <= 7 && col >= 3) || col == 3 && row <= 5 || col == 7 && row >= 5) {
system.out.print("* ");
} else {
system.out.print(" ");
}
}
system.out.println();
}
}
private static void number4() {
for (int row = 1; row <= 9; row++) {
for (int col = 1; col <= 9; col++) {
if (col == 1 && row <= 5 || col == 5 || row == 5) {
system.out.print("* ");
} else {
system.out.print(" ");
}
}
system.out.println();
}
}
private static void number3() {
for (int row = 1; row <= 9; row++) {
for (int col = 1; col <= 9; col++) {
if (row == 1 && (col <= 7 && col >= 3) || row == 5 && (col <= 7 && col >= 3)
|| row == 9 && (col <= 7 && col >= 3) || col == 7) {
system.out.print("* ");
} else {
system.out.print(" ");
}
}
system.out.println();
}
}
private static void number2() {
for (int row = 1; row <= 9; row++) {
for (int col = 1; col <= 9; col++) {
if (row == 1 || col == 9 && row <= 5 || row == 5 || col == 1 && row >= 5 || row == 9) {
system.out.print("* ");
} else {
system.out.print(" ");
}
}
system.out.println();
}
}
private static void number1() {
for (int row = 1; row <= 9; row++) {
for (int col = 1; col <= 9; col++) {
if (row == 9 || col == 5 || row + col == 6 && row <= 3) {
system.out.print("* ");
} else {
system.out.print(" ");
}
}
system.out.println();
}
}
}
>
package afterfeb13;
//54321 star
public class forpatternstar {
public static void main(string[] args) {
for (int row = 5; row >= 1; row--) {
for (int col = 1; col <= row; col++) {
system.out.print("* ");
}
system.out.println();
}
}
}
以上就是forloop-pattern用于数字;星形图案的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号