• Post Reply Bookmark Topic Watch Topic
  • New Topic

Compiling-running problem in Cmd (error: class, interface, or enum expected)  RSS feed

 
Christos Papatasopoulos
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
public class FizzBuzz {

public static void main(String[] args) {

for(Integer i = new Integer(1); i < 61; i++){
if(i % 3 == 0){
System.out.print("Fizz");
}
if(i % 5 == 0){
System.out.print("Buzz");
}

if(i % 3 != 0 && i % 5 != 0){
System.out.print("i");
}
System.out.println();
}
}
}


when I try to compile the java program in command prompt and type javac FizzBuzz.java this comes up:
FizzBuzz.java:19: error: class, interface, or enum expected
}
^
1 error

I shouldnt but I tried typing FizzBuzz.java then to see what's working and then I got this:
Error: LinkageError occurred while loading main class FizzBuzz
        java.lang.ClassFormatError: Incompatible magic value 1886741100 in class file FizzBuzz


I've tried searching for and correcting many possible syntax mistakes and it still doesnt compiling properly
 
Yosuf Ibrahim
Ranch Hand
Posts: 128
4
Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Here is your code, i changed nothing just fixed the identations and it compiled perfectly no issues for me. Here is the result:


 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yosuf Ibrahim wrote:. . . i changed nothing . . .
You did change something; you added a package declaration. You also corrected the compiler error without explaining it.

I can see more possible errors in that code, even though it appears to run.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!