Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/396.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JAVA中断while循环_Java - Fatal编程技术网

JAVA中断while循环

JAVA中断while循环,java,Java,如何制作一个程序,提示用户输入行数和列数,并使用while循环从这些行和列中生成的*输出类似空心矩形的图形 Scanner stdin = new Scanner(System.in); System.out.println("Enter number of rows and columns: "); int row = stdin.nextInt(); int column = stdin.nextInt(); int m = 1; whi

如何制作一个程序,提示用户输入行数和列数,并使用while循环从这些行和列中生成的*输出类似空心矩形的图形

   Scanner stdin = new Scanner(System.in);

    System.out.println("Enter number of rows and columns: ");

    int row = stdin.nextInt();
    int column = stdin.nextInt();

    int m = 1;

    while(m <= column)
    {
        while(m <= row)
        {
            System.out.println("*\t");
        }
        System.out.print("*");
        m++;
    }

Mike您必须使用不同的变量进行差分循环控制。 创建一个n,它应该可以工作


你已经做到了。您现在的问题是什么?只要行>1,您的内部循环将永远运行。不要在内部循环中使用与外部循环相同的变量。@CollinD我不明白我的内部循环将如何永远运行。m将始终是@CollinD哦,好的,太好了!另外,我如何格式化它,使它始终看起来像一个矩形?太好了,谢谢!现在我怎样才能让m的打印语句也显示在顶部呢?当你说:让m的打印语句出现时,你的确切意思是什么?我的意思是最后一行如何打印列中有多少符号在我开始打印行之前如何对第一行执行相同的操作。。所以它看起来像一个矩形,只打印第一行、第一行、最后一行和最后一列。像这样的'ifn==1 | | n==row System.out.println\t;ifm==1 | | m==column System.out.print`
Scanner stdin = new Scanner(System.in);
System.out.println("Enter number of rows and columns: ");

int row = stdin.nextInt();
int column = stdin.nextInt();

int m = 1;
int n = 1;

while(m <= column)
{
    while(n <= row)
    {
        System.out.println("*\t");
        n++;
    }
    System.out.print("*");
    m++;
}