三角形图案
public class TriangleDemo
{
public static void main(String[] args)
{
/*
输出三角形图案
*/
//SB版
//System.out.println("☆");
//System.out.println("☆☆");
//System.out.println("☆☆☆");
//System.out.println("☆☆☆☆");
//System.out.println("☆☆☆☆☆");
//2B版
/*int j = 1;
for (int i = 1;i <= j;i ++ )
{
System.out.println("☆");
}
j ++;
for (int i = 1;i <= j;i ++ )
{
System.out.print("☆");
}
System.out.println();
j ++;
for (int i = 1;i <= j;i ++ )
{
System.out.print("☆");
}
System.out.println();
j ++;
for (int i = 1;i <= j;i ++ )
{
System.out.print("☆");
}
System.out.println();
j ++;
for (int i = 1;i <= j;i ++ )
{
System.out.print("☆");
}
*/
//优化版
for (int j = 1;j <= 5 ; j ++ )
{
for (int i = 1;i <= j;i ++ )
{
System.out.print("☆");
}
System.out.println();
}
}
}
99乘法表
public class Table99Demo
//输出99乘法表
/*
System.out.println(1*1=1);
System.out.println(1*2=2 2*2=4);
System.out.println(1*3=3 2*3=6 3*3=9);
*/
//规律:第二个乘数和行数相同,第一个乘数<=第二个乘数
{
public static void main(String[] args)
{
//2B版
/*
int j = 1;
for (int i =1;i <= j ;i ++ )
{
System.out.print(i + "*" + j + "=" + (i * j));
}
System.out.println();
j ++;
for (int i =1;i <= j ;i ++ )
{
System.out.print(i + "*" + j + "=" + (i * j) + " ");
}
System.out.println();
j ++;
for (int i =1;i <= j ;i ++ )
{
System.out.print(i + "*" + j + "=" + (i * j) + " ");
}
System.out.println();
*/
//优化版
for (int j = 1;j <= 9 ;j ++ )
{
for (int i =1;i <= j;i ++ )
{
System.out.print(i + "*" + j + "=" + (i * j) + " ");
}
System.out.println();
}
}
}
网友评论