Friday, 23 December 2016

Java Program To Display Size Of Different Datatype

Problem :- Write A Java Program To Display Size Of Different Datatype. Here one thing noted down size of Datatype maybe depend upon your Operating System . Operating System You Are using maybe 32 Bit Or 64 Bit  

Logic :- For This Type of problem C++ Can Handle Easily .C++ have a "sizeof" Operator to find a size of any datatype  Follow Given A Syntax

Syntax :-  sizeof( datatype ) 

Replace Datatype by following datatype

int
float
double
long double
long long

See Also :- C++ Program To Display Size Of Different Datatype

Solution :- 

/*Program By Ghanendra Yadav
   Visit http://www.programmingwithbasics.com/
*/
import java.util.*;
class SizeofdataTypes
{
  public static void main (String[] args)
  {
    System.out.println("Size of int: " + (Integer.SIZE/8) + " bytes.");
    System.out.println("Size of long: " + (Long.SIZE/8) + " bytes.");
    System.out.println("Size of char: " + (Character.SIZE/8) + " bytes.");
    System.out.println("Size of float: " + (Float.SIZE/8) + " bytes.");
    System.out.println("Size of double: " + (Double.SIZE/8) + " bytes.");
  }

}

See Also :- C Program To Display Size Of Different Datatype



Output :- 

Java Program To Display Size Of Different Datatype

No comments:
Write comments

Recommended Posts × +