import java.util.Scanner;
class XuXI_01
{
public static void main(String[] args)
{
a:while(true){
System.out.println("please key in m m=1 or m=2");
System.out.println("please key in n");
Scanner sc = new Scanner(System.in);
int m=sc.nextInt();
int n=sc.nextInt();
if(m==1||m==2){
switch(m)
{
case 1:
int a=n;
System.out.println(sanjiao(a));break;
case 2:
int b=n;
System.out.println(jinzita(b));break;
}}
else{System.out.println("please key in right num");
continue a;}}
}
static int sanjiao(int a)
{
int i=0;
if(a%2==0)
{
while(i<a)
{
for(int j=0;j<i;j++)
{
System.out.print("*");
}i++;System.out.println();
}
}
else
{
while(i<a)
{
for(int j=a-i;j>0;j--)
{
System.out.print("*");
}
i++;System.out.println();
}
}return 0;
}
static int jinzita(int b){
for(int i=0;i<=b;i++)
{
for(int j=0;j<=b-i;j++)
{
System.out.print(" ");
}
for(int a=b-i+1;a<=b+i-1;a++)
{
System.out.print("*");
}
System.out.println();
}
return 0;
}
} |