如何制作这样的模式
验证号码必须为奇数
(*)通过输入奇数
向右移动到目前为止这是我的代码
import java.util.Scanner;
public class Patern {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int z;
int a,b;
do
{
System.out.print("Input Odd Number : ");
z= input.nextInt();
}
while (z %2 == 0);//validate input number
for(a=1;a<z;a++)
{
for(b=1; b<=z;b++)
if (b==1 || a==z|| a==b)
{
System.out.print(" * ");
}
else if (b==2 || a==z|| a==b)
{
System.out.print(" * ");
}
else
{
System.out.println(" * ");
System.out.println("");
}
}
}
}
答案 0 :(得分:-1)
public class Test {
public static void main(String[] args) {
draw(11);
}
public static void draw(int n){
for (int i=0;i<n;i++) {
for (int j=0;j<n;j++) {
if(i==0 || i==j || i == n-1 || i ==(n-1)/2 || i == n-j-1 || j==0 || j==n-1 || j == (n-1)/2){
System.out.print("* ");
}else{
System.out.print(" ");
}
}
System.out.println();
}
}
}