Do ternary operators work here?

+1 vote
asked Jan 19 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 by zemiak (430 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.
...