+ 1

question about running java in Dcoder

public class ExampleProgram { public static void main(String[ ] args) { System.out.println("Hello World"); } } I ran this code in Dcoder java ide,and got this output:source_file.java:1: error: class ExampleProgram is public, should be declared in a file named ExampleProgram.java public class ExampleProgram { ^ 1 error I do save the file with the same name of the class "ExampleProgram",so did I miss something else to make it work.

1st May 2017, 9:21 AM
Chain Leang
Chain Leang - avatar
3 Antworten
+ 4
OK,I found the answer,it should be "class Dcoder" not "public class" ,not other class name in main
2nd May 2017, 2:44 AM
Chain Leang
Chain Leang - avatar
+ 1
I saved the file as you said and it didn't work,then I intent to move the file from Dcoder work folder to somewhere like /sdcard in my phone for compiling it ,but it is not permitted
1st May 2017, 10:26 AM
Chain Leang
Chain Leang - avatar
0
Save it as ExampleProgram.java this is the way it should work.
1st May 2017, 9:30 AM
Ekagra Sinha
Ekagra Sinha - avatar