Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

Can Online GBD compile the Enhanced java switch statement?

+2 votes
asked Jun 8, 2023 by Lawrence W (Larryrick1) (160 points)
public class Main {

public static void main(String[] args) {

// Enhanced Switch statement

    int switchValue = 3;

    

    switch (switchValue) {

        case 1 -> System.out.println("Value was 1");

        case 2 -> System.out.println("Value was 2");

        case 3, 4, 5 -> {

            System.out.println("Was a 3, a 4, or a 5");

            System.out.println("Actually it was a " + switchValue);

        }

        default -> System.out.println("Was not 1, 2, 3, 4, or 5");

    }// end switch

    }// end method main

}//end class Main

1 Answer

+1 vote
answered Jun 8, 2023 by Peter Minarik (86,640 points)

I'm not a Java programmer...

It looks like the change you're talking about was introduced in Java 14.0.

If I look at the Java compiler in OnlineGDB, it says javac 11.0.4, so I guess OnlineGDB does not support Java 14 (yet).

Maybe an administrator can answer your question.

commented Jun 8, 2023 by Lawrence W (Larryrick1) (160 points)
Thank you for your reply!  After some experimentation, I was able to compile the program using IntelliJ IDEA.
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...