废话不多说,直接上干货
方法一:感觉不够优化
import java.util.Scanner;
class Day405
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("请输入行数");
int h=sc.nextInt();
for (int x=0 ;x<h ;x++ )
{
for (int y =x;y<h ;y++ )
{
System.out.print(" ");
}
for (int y =0;y<=x ;y++ )
{
System.out.print("*");
}
for (int y =1;y<=x ;y++ )
{
System.out.print("*");
}
System.out.println();
}
}
}
方法二:感觉u充实的感觉三角形打的太空了,
import java.util.Scanner;
class Day405
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
System.out.println("请输入行数");
int h=sc.nextInt();
for (int x=0 ;x<h ;x++ )
{
for (int y =x;y<h ;y++ )
{
System.out.print(" ");
}
for (int y =0;y<=x ;y++ )
{
System.out.print("* ");
}
System.out.println();
}
}
}
|
|