Saturday, May 11, 2019

What do you think the output will be for the following code?

Problem statement:
Can you let me know the output of the following code?
  1. public class ExecutionTwo {
  2.     public static void main(String[] args) {
  3.         // primitive data type
  4.         double d1 = 0.8;
  5.         double d2 = 0.8;
  6.         System.out.println(d1 == d2);
  7.         double d3 = 0.8d;
  8.         double d4 = 0.8d;
  9.         System.out.println(d3 == d4);
  10.         double d5 = 0.8D;
  11.         double d6 = 0.8D;
  12.         System.out.println(d5 == d6);
  13.         // Wrapper class
  14.         Double d7 = 0.8;
  15.         Double d8 = 0.8;
  16.         System.out.println(d7.equals(d8));
  17.         Double d9 = 0.8d;
  18.         Double d10 = 0.8d;
  19.         System.out.println(d9.equals(d10));
  20.         Double d11 = 0.8D;
  21.         Double d12 = 0.8D;
  22.         System.out.println(d11.equals(d12));
  23.     }
  24. }
Output:
true
true
true
true
true
true

No comments:

Post a Comment

Blueprint for self-improvement

To learn faster: Make the process fun To understand yourself : Write To understand the world better : Read To build deeper connection : Lis...