Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Online Java Compiler Issue: Code Not Executing as Expected

LakshitLakshit Member
edited November 2023 in Programming

I'm using this online Java compiler for my project, and I'm encountering unexpected behavior in the execution of my code. Here's a simplified snippet:

[code]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());

    }

  }

}

[/code]

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?

Sign In or Register to comment.