New to Replit. Having problems executing code

I created a new file and code, but unable to execute the code.*

Repl link:

public class FloatingPoint {
  public static void main(String[] args) {
    float sampleFloatValue = 0.123456789f;
    double sampleDoubleValue = 0.123456789;
    System.out.println("Value as float:  " + sampleFloatValue);
    System.out.println("Value as double: " + sampleDoubleValue);
  }
}
Java FloatingPoint.java

This is the error I get:

 sh -c javac -classpath .:target/dependency/* -d . $(find . -type f -name ‘*.java’)
./FloatingPoint.java:9: error: class, interface, enum, or record expected
Java FloatingPoint.java;
^
1 error
exit status 1

I can only seem to run the code if I edit the Main. java file

1 Like

Hey @PeterH17, welcome to the community!

Running the Main.java file is intentional, since the Repl is only expected to run one file at the time, usually the main one.

You can change which file you can run, but it’s very technical and not recommended. So instead, I suggest you to import the file into your Main.java like so:

Main.java

import fp.FloatingPoint;

// …

FloatingPoint.java

package fp;

// …
1 Like

Hey savardo,

Thank you for your advice. That makes sense.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.