Java 使用for循环和while循环创建2个三角形
当用户输入带有n的循环时,尝试使用for和打印出2个三角形。Java 使用for循环和while循环创建2个三角形,java,Java,当用户输入带有n的循环时,尝试使用for和打印出2个三角形。 但是while循环我无法让它打印出三角形 应该是这样的: n=3 *X *X X *X X X *X *X X *X X X 但它是这样打印出来的 X X X X X X X X X X X X import java.util.*; 公共阶级三角 { 公共静态void main(字符串[]args) { 扫描仪输入=新扫描仪(System.in); int n,number,count=0,count1; System.out.
但是while循环我无法让它打印出三角形 应该是这样的:
n=3
*X
*X X
*X X X
*X
*X X
*X X X
但它是这样打印出来的
X
X X
X X X
X
X
X
X
X
X
import java.util.*;
公共阶级三角
{
公共静态void main(字符串[]args)
{
扫描仪输入=新扫描仪(System.in);
int n,number,count=0,count1;
System.out.print(“请输入整数:”);
n=input.nextInt();
如果(n>0)
{
for(int i=1;i查看一下while循环。内部while循环中有System.out.println(“”;
)。与for循环的版本一样,应在处理内部while循环后调用System.out.println(“”;
)
while(count<n) //outer
{
count = count +1;
count1 = 0;
while(count1 < count) //inner
{
System.out.print(" X");
count1 = count1 + 1;
}
System.out.println(""); // Thats the right place.
}
while(计数)