Problem:- Java Program to Find Size of Different Data type or Find Size of Primitive Data Type in Java or Data types in java with example programs or java Program to Find the Size of int, float, double and char or Java Variables and (Primitive) Data Types or how to find size of variable in java or Find Size of Primitive Data Type in Java or How to find the integer length in java? or size of the variable in java.Write A Java Program To Display Size Of Different Datatype.
Logic:- As we know that C++ has a "sizeof" operator to find a size of any data type or variable. But in Java, we can find the size of a variable by this (Integer.SIZE/8), I want to clear one thing the size of data type maybe depend upon your operating system ( you Are using maybe 32 Bit or 64 Bit ). Below is a syntax of sizeof operator in C++.
Syntax:- sizeof( datatype )
Just replace datatype in above syntax by the following datatype and you are done, size operator displays the size of each variable on the screen.
int
float
double
long double
long long
For Java, the syntax is below you have to only change the datatype but real data type name.
(datatype.size/8)
(Integer.SIZE/8)
(Long.SIZE/8)
(Character.SIZE/8)
(Float.SIZE/8)
(Double.SIZE/8)
See Also:- C++ Program To Display Size Of Different Datatype
See Also:- C Program To Display Size Of Different Datatype
Output:-
1. Java Program To Check Character Is Uppercase, Lowercase Alphabet Or A Digit Or A Special Symbol
2. Java Program To Find Greatest Among Three Numbers
3. Java Program For Find The Salary Of An Employee With Employee Grade
4. Java Program To Calculate Factorial Of A Given Number
5. Java Program For Calculate Percentage Of 5 Subjects
Logic:- As we know that C++ has a "sizeof" operator to find a size of any data type or variable. But in Java, we can find the size of a variable by this (Integer.SIZE/8), I want to clear one thing the size of data type maybe depend upon your operating system ( you Are using maybe 32 Bit or 64 Bit ). Below is a syntax of sizeof operator in C++.
Syntax:- sizeof( datatype )
Just replace datatype in above syntax by the following datatype and you are done, size operator displays the size of each variable on the screen.
int
float
double
long double
long long
For Java, the syntax is below you have to only change the datatype but real data type name.
(datatype.size/8)
(Integer.SIZE/8)
(Long.SIZE/8)
(Character.SIZE/8)
(Float.SIZE/8)
(Double.SIZE/8)
See Also:- C++ Program To Display Size Of Different Datatype
Java Program to Find Size of Different Datatype
import java.util.*; /* Program By Ghanendra Yadav Visit http://www.programmingwithbasics.com/ */ 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:-
You May Also See
1. Java Program To Check Character Is Uppercase, Lowercase Alphabet Or A Digit Or A Special Symbol
2. Java Program To Find Greatest Among Three Numbers
3. Java Program For Find The Salary Of An Employee With Employee Grade
4. Java Program To Calculate Factorial Of A Given Number
5. Java Program For Calculate Percentage Of 5 Subjects
it is very usefull for me thank you
ReplyDeleteThanks
Deletesukanyathota12@gmail.com
ReplyDelete