我的程序嵌套在java中的do-while循环中时不会重复

我的程序嵌套在java中的do-while循环中时不会重复,java,while-loop,do-while,Java,While Loop,Do While,我想让这个程序使用do-while循环重复它自己。但是,当我运行它时。我得到的只是错误。有什么帮助吗 int Col = in.nextInt(); int Row = in.nextInt(); do { //Start of the do loop here System.out.print(" * "); for(int i = 1; i<=Row;i++ ) { Syste

我想让这个程序使用do-while循环重复它自己。但是,当我运行它时。我得到的只是错误。有什么帮助吗

        int Col = in.nextInt();
        int Row = in.nextInt();

        do { //Start of the do loop here
        System.out.print("   *  ");
        for(int i = 1; i<=Row;i++ ) {
           System.out.format("%4d",i);
        }
        System.out.println();
        System.out.println("------------------------------------------");

        for(int i = 1; i<=Col; i++) {
        System.out.format("%4d |",i);
        for(int j=1; j<=Row; j++) {
            System.out.format("%4d",i*j);
            }
        System.out.println();
      } while (!(Col = 0) && !(Row = 0));// This is the while loop
}
}让我们看看代码中发生了什么:

首先,在代码的下面部分,您从未关闭过外部循环

for(int i = 1; i<=Col; i++) {
        System.out.format("%4d |",i);
        for(int j=1; j<=Row; j++) {
            System.out.format("%4d",i*j);
            }
        System.out.println();
} <----need this 
第三,

这里

这是错误的,因为您将零指定给列和列,但编译器正在寻找布尔结果


代码中有多个语法错误。如果你真的给出了错误,这会有所帮助

while语句位于for循环的右大括号中。那没有任何意义。此外,Java不允许在表达式内部使用赋值运算符。事实上,这是特别禁止的,以防止您在比较两个值的等效性时犯赋值错误。还有一组不平衡的大括号,其中两个没有在代码块内格式化。您的代码缩进也很差,因此不平衡的大括号很难实际看到。如果您正确地缩进了代码,那么就更容易看到这些语法错误

我会编辑你的问题,但是这个改变被认为太微不足道了,所以不允许

试试这个:

        int Col = in.nextInt();
        int Row = in.nextInt();

        do { // Start of the do loop here
            System.out.print("   *  ");
            for(int i = 1; i<=Row; i++) {
               System.out.format("%4d", i);
            }
            System.out.println();
            System.out.println("------------------------------------------");

            for(int i = 1; i<=Col; i++) {
                System.out.format("%4d |",i);
                for(int j=1; j<=Row; j++) {
                    System.out.format("%4d",i*j);
                }
                System.out.println();
            }
        } while (Col != 0 && Row != 0); // This is the while loop

你会遇到什么错误?你在运行或编译程序时会遇到错误吗?此外,如果您告诉我们这些错误是什么,通常更容易解决这些错误。最后:使用==:例如Col==0检查变量是否等于值。尝试格式化代码并缩进它。您缺少“do”语句的右大括号。还有,错误是什么?乍一看,如果这是你的全部代码,看起来你的大括号没有对齐,而你的while在错误的右大括号上。
while (!(Col = 0) && !(Row = 0));
do
{
   //Statements
}while(Boolean_expression); <-- need boolean experssion 
} while (Col != 0 && Row != 0);
        int Col = in.nextInt();
        int Row = in.nextInt();

        do { // Start of the do loop here
            System.out.print("   *  ");
            for(int i = 1; i<=Row; i++) {
               System.out.format("%4d", i);
            }
            System.out.println();
            System.out.println("------------------------------------------");

            for(int i = 1; i<=Col; i++) {
                System.out.format("%4d |",i);
                for(int j=1; j<=Row; j++) {
                    System.out.format("%4d",i*j);
                }
                System.out.println();
            }
        } while (Col != 0 && Row != 0); // This is the while loop
        int Col = in.nextInt();
        int Row = in.nextInt();

        while (Col != 0 && Row != 0) {
            System.out.print("   *  ");
            for(int i = 1; i<=Row; i++) {
               System.out.format("%4d", i);
            }
            System.out.println();
            System.out.println("------------------------------------------");

            for(int i = 1; i<=Col; i++) {
                System.out.format("%4d |",i);
                for(int j=1; j<=Row; j++) {
                    System.out.format("%4d",i*j);
                }
                System.out.println();
            }
        }