Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Online Java Compiler Issue: Code Not Executing as Expected

  1. #1
    Junior Member
    Join Date
    Sep 2021
    Location
    India
    Posts
    20
    Thanks
    1
    Thanked 2 Times in 2 Posts

    Default Online Java Compiler Issue: Code Not Executing as Expected

    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?

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,162
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Online Java Compiler Issue: Code Not Executing as Expected

    I'm not getting the expected output
    What is the expected output?
    What output are you getting?
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Will online compiler be enough to learn java?
    By Omar Kairatuly in forum Java Theory & Questions
    Replies: 1
    Last Post: November 27th, 2023, 06:38 AM
  2. [SOLVED] For loop not executing as expected - Very simple coding
    By LyndonS in forum Loops & Control Statements
    Replies: 11
    Last Post: February 1st, 2021, 09:09 PM
  3. Re: }while(guess1!=gen1) ';' expected Compiler error
    By morrism35 in forum What's Wrong With My Code?
    Replies: 11
    Last Post: October 3rd, 2014, 10:55 PM
  4. Java Online Compiler
    By sb24 in forum Java Theory & Questions
    Replies: 15
    Last Post: March 23rd, 2012, 09:50 AM
  5. [SOLVED] Help figuring out why my method isn't executing as expected.
    By Herah in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 8th, 2011, 05:27 PM