Output writing based on summation of different data types. – Computer Sir Ki Class

Login


Lost your password?

Don't have an account ?
Register (It's FREE) ×
  

Login
[lwa]



Solved Problem #JAVA#3852    siteicon   siteicon  

Problem Statement - Output writing based on summation of different data types.

Write output of the following program which is based on summation of different data types.

class SP_DataSum
{
  public static void main(String[] args)
  {
    int n=12;
    double d=12.0;
    float f=12.0f;
    byte b=12;
    char c=12;
    System.out.println(n+d+f+b+c);
  }
}

 

Solution

TC++ #3852

Run Output

60.0

int n=12; double d=12.0; float f=12.0f; byte b=12; char c=12;
Values of different data types have been initialised.

System.out.println(n+d+f+b+c);

The largest of the type here will be resulted. So this sum would be 60.0 and not 60.

Common Errors

  • Some time students erroneously write it as 60 and not 60.0


Suggested Filename(s): BooleanType.java



Share

sunmitra| Created: 19-Mar-2018 | Updated: 27-Nov-2019|






Back