Java 臭名昭著的三角环。。。扭曲
所以我必须输出一个直角三角形的星号。。。有边界。三角形我可以做的没有问题,但是边界给我带来了困难。我在循环中考虑另一个if/else,但我不知道如何表达它。我想要的结果是:Java 臭名昭著的三角环。。。扭曲,java,Java,所以我必须输出一个直角三角形的星号。。。有边界。三角形我可以做的没有问题,但是边界给我带来了困难。我在循环中考虑另一个if/else,但我不知道如何表达它。我想要的结果是: ******* * ***** * **** * *** * ** * * ******* 没有帮助我能得到的是: ******* ***** **** *** ** * 这是我的代码: public class Pattern { public st
*******
* *****
* ****
* ***
* **
* *
*******
没有帮助我能得到的是:
*******
*****
****
***
**
*
这是我的代码:
public class Pattern
{
public static void main(String[] args)
{
final int WIDTH = 7;
for (int row = 1; row <= (WIDTH); row++)
{
for (int col = 1; col <= (WIDTH); col++)
{
if (row <= col)
{
System.out.print("*");
}
else
{
System.out.print(" ");
}
}
System.out.println();
}
System.out.println("\n\nGoodbye!");
}
}
公共类模式
{
公共静态void main(字符串[]args)
{
最终整数宽度=7;
对于(int row=1;rowHint),边框始终位于第一个索引和最后一个索引上
保持打开状态:D试试这个:)
publicstaticvoidmain(字符串[]args){
最终整数宽度=7;
对于(int row=1;row这应该可以工作
public class Pattern
{
public static void main(String[] args)
{
final int WIDTH = 7;
for (int row = 1; row < (WIDTH); row++)
{
System.out.print("*");
for (int col = 1; col < (WIDTH); col++)
{
if (row <= col)
{
System.out.print("*");
}
else
{
System.out.print(" ");
}
}
System.out.println("");
}
for(int i = 1; i <= (WIDTH); i++) {
System.out.print("*");
}
System.out.println("\n\nGoodbye!");
}
}
公共类模式
{
公共静态void main(字符串[]args)
{
最终整数宽度=7;
对于(int行=1;行<(宽度);行++)
{
系统输出打印(“*”);
用于(整数列=1;列<(宽度);列++)
{
如果(行)非常接近。现在想想三角形的对称属性。你知道它有多长、多宽,你需要镜像边框……你想在每行的开始处打印一个*
,或者你不想以这种方式打印0、1、2、.5。。。
public class Pattern
{
public static void main(String[] args)
{
final int WIDTH = 7;
for (int row = 1; row < (WIDTH); row++)
{
System.out.print("*");
for (int col = 1; col < (WIDTH); col++)
{
if (row <= col)
{
System.out.print("*");
}
else
{
System.out.print(" ");
}
}
System.out.println("");
}
for(int i = 1; i <= (WIDTH); i++) {
System.out.print("*");
}
System.out.println("\n\nGoodbye!");
}
}