Using question mark if condition in print statement

pandagrammer

I want to print a sentence like:

   boolean someSetting = true; 
   System.out.println("Running experiment " + (someSetting)? "on" : "off");

Obviously this won't compile. Is there any other suggestion to do this?

jmj

add brackets around it to evaluate that expression to String value

System.out.println("Running experiment " + ((someSetting)? "on" : "off"));

without brackets it tries to contact (+) String and boolean and puts it as a conditional expression which is invalid

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

question mark in IN statement

From Dev

question mark in IN statement

From Dev

Prepared statement without question mark placeholder

From Dev

SQLite Error in statement insert with question mark

From Dev

Why string with question mark (?) is not printed in the for batch statement

From Dev

Using a question mark as a String in android

From Dev

Question mark on filename using fopen

From Dev

Question mark on filename using fopen

From Dev

How to forward a directory using htaccess with a question mark in it?

From Dev

Remove question mark from url using htaccess

From Dev

Match Question Mark in rewrite rule using .htaccess

From Dev

remove the question mark from url using htaccess

From Dev

Remove question mark from url using htaccess

From Dev

Add Question Mark to ARFF Using Java code

From Dev

Redirect 301 url with question mark using htaccess

From Dev

How do I escape a literal question mark ('?') in a JDBC prepared statement

From Dev

Using the guard condition in the body of statement

From Dev

Matlab: using a string as condition for if statement

From Dev

Using contents of string as condition in if statement

From Dev

multiple condition using range in if statement

From Dev

using lambda together with a condition statement

From Dev

Using an item in an array in a condition statement

From Dev

How to print a statement using ArrayOutOfBoundException

From Dev

using .htaccess to 410 any wildcard url that contains a question mark

From Dev

How to escape asterisk and question mark using RLIKE in PDO?

From Dev

Filemaker SQL query with question mark in column name using JDBC

From Dev

display results with question mark other than english using php and ajax

From Dev

Prepared statements: Using unnamed and unnumbered question mark style positional placeholders

From Dev

snprintf is returning a string containing a question mark when using a float

Related Related

  1. 1

    question mark in IN statement

  2. 2

    question mark in IN statement

  3. 3

    Prepared statement without question mark placeholder

  4. 4

    SQLite Error in statement insert with question mark

  5. 5

    Why string with question mark (?) is not printed in the for batch statement

  6. 6

    Using a question mark as a String in android

  7. 7

    Question mark on filename using fopen

  8. 8

    Question mark on filename using fopen

  9. 9

    How to forward a directory using htaccess with a question mark in it?

  10. 10

    Remove question mark from url using htaccess

  11. 11

    Match Question Mark in rewrite rule using .htaccess

  12. 12

    remove the question mark from url using htaccess

  13. 13

    Remove question mark from url using htaccess

  14. 14

    Add Question Mark to ARFF Using Java code

  15. 15

    Redirect 301 url with question mark using htaccess

  16. 16

    How do I escape a literal question mark ('?') in a JDBC prepared statement

  17. 17

    Using the guard condition in the body of statement

  18. 18

    Matlab: using a string as condition for if statement

  19. 19

    Using contents of string as condition in if statement

  20. 20

    multiple condition using range in if statement

  21. 21

    using lambda together with a condition statement

  22. 22

    Using an item in an array in a condition statement

  23. 23

    How to print a statement using ArrayOutOfBoundException

  24. 24

    using .htaccess to 410 any wildcard url that contains a question mark

  25. 25

    How to escape asterisk and question mark using RLIKE in PDO?

  26. 26

    Filemaker SQL query with question mark in column name using JDBC

  27. 27

    display results with question mark other than english using php and ajax

  28. 28

    Prepared statements: Using unnamed and unnumbered question mark style positional placeholders

  29. 29

    snprintf is returning a string containing a question mark when using a float

HotTag

Archive