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.

Do ternary operators work here?

+1 vote
asked Jan 19, 2020 by anonymous
public class Main

{

boolean yes = true;

System.out.println(yes ? "Hello" : "Good bye");

}

The above code will not compile. Does this compiler allow for ternary operators?

1 Answer

+1 vote
answered Jan 25, 2020 by zemiak (490 points)

do it in some method :

public class Main {
   public static void main(String[] args) {
        boolean yes = true;
        System.out.println(yes ? "Hello" : "Good bye");
    }
}

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.
...