简体   繁体   English

java中的编译器错误:需要标识符

[英]Compiler error in java: identifier expected

At the line在一线

for(int x,=0; x<=numberOfLockers; x++);

I get an identifier expected error.我收到一个标识符预期错误。 What's wrong there?有什么问题吗? This is my code:这是我的代码:

public static void main(String[] args) {
    Scanner console = new Scanner(System.in);   
    int studentVisitCount = 0;   

    System.out.print("Enter the number of lockers: ");   
    int x = 0;
    int y = 0;
    int numberOfLockers = console.nextInt();   

    for(int x,=0; x<=numberOfLockers; x++);
    {
        if(x%y==0)
        {
            studentVisitCount++;
        }
        for(int y=0; y<=x; y++)
        {
            if(studentVisitCount%2!=0)
            {
                System.out.print(y+" ");
            }
        }
    }

    System.out.println("The number of lockers and students are: "+numberOfLockers);   
    System.out.print("The locker numbers of lockers that are left open at the end of the game are: ");  
}

Welcome to the community!欢迎来到社区!

You have basically answered your question.你基本上已经回答了你的问题。 You have a trivial syntax error in your for-loop.您的 for 循环中有一个微不足道的语法错误。

for(int x,=0; x<=numberOfLockers; x++);
         ^
      remove ','

Please brush up on your basic Java.请复习您的基本 Java。

Cheers!干杯!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM