CSDN one-click annotation function

What kind of awesome function is this
? See here:
Insert image description here

Then:Insert image description here

Try another one:

输出结果是?

package yuyi03.interview;

/**
 * ClassName: InterviewTest2
 * Package: yuyi03.interview
 * Description:
 *
 * @Author 雨翼轻尘
 * @Create 2023/12/14 0014 0:08
 */
public class InterviewTest2 {
    
    
    public static void main(String[] args) {
    
    
        //题目1:
        int i = 10;
        double d = 10.2;
        System.out.println(i == d);	//地址不相同,结果为false
        
        //题目2:
        Integer i1 = 10;
        Double d1 = 10.2;
        //System.out.println(i1 == d1);	//编译报错

        //题目3:
        Integer m = 1000;
        double n = 1000;
        System.out.println(m == n);//true

        //题目4:
        Integer x = 1000;
        int y = 1000;
        System.out.println(x == y);//true
    }
}
————————————————
版权声明:本文为CSDN博主「雨翼轻尘」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/m0_55746113/article/details/134990781

Then "One-click annotation" displays:
Insert image description here

This content contains code.

Code analysis is explained as follows:

Question 1: Compare whether the values ​​of an int type variable i and a double type variable d are equal. Since the types of i and d are different, the compiler will perform type conversion and convert i to double type for comparison. Since the integer 10 can be represented exactly as the floating point number 10.0, the result of i == d is true.

Question 2: Try to compare whether the values ​​of an Integer type object i1 and a Double type object d1 are equal. Since i1 and d1 have different types, the compiler will perform type conversion. However, in Java, the Integer type and the Double type are not directly comparable, so an error will be reported.

Question 3: Compare whether the values ​​of an Integer type object m and a double type variable n are equal. Since the types of m and n are different, the compiler will perform type conversion and convert m to double type for comparison. Since the integer 1000 can be represented exactly as a floating point number 1000.0, the result of m == n is true.

Question 4: Compare the values ​​of an object x of type Integer and a variable y of type int to see if they are equal. Since x and y are both integer types, they can be compared directly. Since the values ​​of x and y are both 1000, the result of x == y is true.

The code after adding comments is as follows:


package yuyi03.interview;

/**
 * ClassName: InterviewTest2
 * Package: yuyi03.interview
 * Description: 
 * 
 * @Author 雨翼轻尘
 * @Create 2023/12/14 0014 0:08
 */
public class InterviewTest2 {
    
    
    public static void main(String[] args) {
    
    
        //题目1:比较一个int类型的变量i和一个double类型的变量d的值是否相等。由于i和d的类型不同,编译器会进行类型转换,将i转换为double类型进行比较。由于整数10可以精确表示为浮点数10.0,所以i == d的结果为true。
        int i = 10;
        double d = 10.2;
        System.out.println(i == d);    //地址不相同,结果为false

        //题目2:尝试比较一个Integer类型的对象i1和一个Double类型的对象d1的值是否相等。由于i1和d1的类型不同,编译器会进行类型转换。但是在Java中,Integer类型和Double类型是不可直接比较的,所以会报错。
        Integer i1 = 10;
        Double d1 = 10.2;
        //System.out.println(i1 == d1);    //编译报错

        //题目3:比较一个Integer类型的对象m和一个double类型的变量n的值是否相等。由于m和n的类型不同,编译器会进行类型转换,将m转换为double类型进行比较。由于整数1000可以精确表示为浮点数1000.0,所以m == n的结果为true。
        Integer m = 1000;
        double n = 1000;
        System.out.println(m == n);//true

        //题目4:比较一个Integer类型的对象x和一个int类型的变量y的值是否相等。由于x和y都是整数类型,可以直接进行比较。由于x和y的值都是1000,所以x == y的结果为true。
        Integer x = 1000;
        int y = 1000;
        System.out.println(x == y);//true
    }
}

What do you think of this feature?

Guess you like

Origin blog.csdn.net/m0_55746113/article/details/134999240