program: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();
}
}
}
program:2
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();
}
}
}
program:3
package afterfeb13;
public class forpattern12345 {
public static void main(String[] args) {
for (int row = 1; row <= 5; row++) {
for (int col = 1; col <= row; col++) {
System.out.print("* ");
}
System.out.println();
}
}
}
Top comments (0)