Can (a==1 && a==2 && a==3) evaluate to true in Java?

后端 未结 8 733
梦如初夏
梦如初夏 2020-11-29 15:01

We know it can in JavaScript.

But is it possible to print \"Success\" message on the condition given below in Java?

if (a==1 && a==2 &&am         


        
8条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-29 15:21

    In this question @aioobe suggests (and advise against) the use of C preprocessor for Java classes.

    Although it is extremely cheaty, that's my solution:

    #define a evil++
    
    public class Main {
        public static void main(String[] args) {
            int evil = 1;
            if (a==1 && a==2 && a==3)
                System.out.println("Success");
        }
    }
    

    If executed using the following commands it will output exactly one Success:

    cpp -P src/Main.java Main.java && javac Main.java && java Main
    

提交回复
热议问题