Computing

Online Java Compiler Issue: Code Not Executing as Expected

Submitted by hermit21, , Thread ID: 279518

hermit21
Lurker
Level:
0
Reputation:
0
Posts:
1
Likes:
0
Credits:
-3
17-11-2023, 07:56 AM
This post was last modified: 17-11-2023, 07:58 AM by hermit21
#1
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());
        }
    }
}

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?

Users browsing this thread: 1 Guest(s)