How to make two files within one project in an online compiler?
Online Java programing IDE with support for multiple files - Code.org Professional Learning Community
Any free, or cheap, online compilers for Python and Java?
java - Solving mismatch exceptions only appearing in one compiler - Stack Overflow
Videos
I'm using an online java compiler on the browser because my school issued laptop does not allow me to download Eclipse. But in this website, I can only have one file. I want to one file for construction and one for running but I'm unable to do it.
I'm trying to make an online editor and compiler for my students to run code on. Yes, there are some out there but they don't fit my needs.
I've been able to use OneCompiler's API through RapidAPI but it costs a bit too much. Is there an open source compiler I can run on a server and connect to? I've tried use Codex-API but can't get the darn thing to work. It needs me to setup a docker container and such but I get errors. Not sure if it's a me thing or not so I'm looking for guidance from y'all with other possible solutions that I might be missing. Thanks.
The error trace seems to indicate that the InputMismatchException is thrown when scan.nextInt() is called.
After your print System.out.println("Would you like to enter another location?");, if the user inputs anything other than an integer, scan.nextInt() will throw an exception. Even if you read the user's input as a string as suggested by someone else, the parseInt method in escape = Integer.parseInt(scan.nextLine()) will throw an error because the string may not be a valid integer.
I suggest adding try-catch block as follows around the scan.nextInt() call so that your program doesn't crash when a user inputs something other than a valid integer (like the number 8.238).
boolean inputValid = false;
System.out.println("Would you like to enter another location?");
while (!inputValid) {
try {
escape = scan.nextInt();
inputValid = true;
} catch (InputMismatchException e) {
inputValid = false;
System.out.println("Please enter a valid Integer");
}
}
This code will continue asking the user until the user enters a valid integer.
It might be because the online scanner's implementation of nextInt() is different and is causing the problems.
Perhaps trying to parse the input as a string and the as a double/int would work:
Scanner scan = new Scanner(System.in);
double x; // the latitude input
double y; // the longitude input
double n = -90; // the maximum north value
double e = -180; // the maximum east value
double s = 90; // the maximum south value
double w = 180; // the maximum west value
int escape = 1; // the value that dictates when it's time to exit the
// while loop
while (escape == 1) {
System.out.println("Please enter the latitude:");
x = Double.parseDouble(scan.nextLine());
System.out.println("Please enter the longitude:");
y = Double.parseDouble(scan.nextLine());
if ((x > n) && (x <= 90))
n = x;
if ((x < s) && (x >= -90))
s = x;
if ((y > e) && (y <= 180))
e = y;
if ((y < w) && (y >= -180))
w = y;
if ((x > 90) || (x < -90) || (y > 180) || (y < -180))
System.out.println("Incorrect Latitude or Longitude");
System.out.println("Would you like to enter another location?");
escape = Integer.parseInt(scan.nextLine());
}
System.out.println("Farthest North: " + n);
System.out.println("Farthest South: " + s);
System.out.println("Farthest East: " + e);
System.out.println("Farthest West: " + w);
Again, this depends on the online scanner's way of doing things.