Java .类预期错误

Java .类预期错误,java,Java,我试图写一些代码来打印出一个由“*”组成的正方形。问题是,在变量“int stars”之后出现了一个错误,即“.class expected”。我不知道这是什么意思 class Main { public static void main( String args[] ) { int sqaure = 5; int line = 1; while ( line <= sqaure ) int stars = 1; while ( stars <= square ) { Sy

我试图写一些代码来打印出一个由“*”组成的正方形。问题是,在变量“int stars”之后出现了一个错误,即“.class expected”。我不知道这是什么意思

class Main
{
public static void main( String args[] )
{


int sqaure = 5;
int line = 1;

while ( line <= sqaure )

int stars = 1;
while ( stars <= square )
{ 
System.out.print( "*" );
stars = stars + 1;
}
System.out.println();
line = line + 1;
}

}
主类
{
公共静态void main(字符串参数[])
{
int sqaure=5;
内线=1;
而(直线现在更好了

忘了

{}
之后

while(行while语法为

while(boolean)
{
//Your code
}

while(line您将问题更改为一个完全不同的问题。事实并非如此,因为此处已有的答案不再是您当前问题的答案

现在变量名中有一个输入错误(
sqaure
vs
square

请使用IDE,因为它将帮助您防止这些讨厌的小错误,并帮助您学习java编程。

class Main
class Main
{
    public static void main( String args[] )
    {

        int square = 5;
        int line = 1;
        int stars = 1;
        while ( line <= square ){
            while ( stars <= square ){ 
                System.out.print( "*" );
                stars = stars + 1;
            }
            System.out.println();
            line = line + 1;
         }
    }

}
{ 公共静态void main(字符串参数[]) { 整数平方=5; 内线=1; int星=1;
虽然(一行缩进强调了这个问题。您需要一个带有代码格式的IDE。缩进中断会使此错误变得明显。请不要将问题更改为完全不同的问题。将其还原为原始问题。如果您需要更多帮助,请打开一个新问题。对不起,您建议使用哪种IDE?我喜欢Eclipse,但不喜欢Netbeans当然,你可以试着看看什么最适合你。IDE的选择其实是个人的事情。我更喜欢在Eclipse上工作,而我的朋友中很少有人会接受IDE以外的任何东西。实际上,这在很大程度上取决于项目环境和个人的便利性…我建议安装(NetBeans和Eclipse在开始和结束时都是根据您的经验决定的……大括号应该在同一行,而不是下一行。)line@AlanFoster:你确定吗?你指的是哪个括号?
class Main
{
    public static void main( String args[] )
    {

        int square = 5;
        int line = 1;
        int stars = 1;
        while ( line <= square ){
            while ( stars <= square ){ 
                System.out.print( "*" );
                stars = stars + 1;
            }
            System.out.println();
            line = line + 1;
         }
    }

}