标题: 关于打印等腰三角形,大神们来指点 [打印本页] 作者: lnscore 时间: 2014-12-18 22:34 标题: 关于打印等腰三角形,大神们来指点 废话不多说,直接上干货
方法一:感觉不够优化
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++ )
{