I'm using Scaler online Java compiler for my project, and I'm encountering unexpected behavior in the execution of my code. Here's a simplified snippet:
import java.util.ArrayList; public class Main { public static void main(String[] args) { ArrayList<String> fruits = new ArrayList<>(); fruits.add("Apple"); fruits.add("Banana"); fruits.add("Orange"); for (String fruit : fruits) { System.out.println(fruit.length()); } } }
Despite the seemingly straightforward code, I'm not getting the expected output. What could be causing this issue with the online Java compiler, and how can I rectify it to ensure proper code execution and output?