Java Data Types Hackerrank Solution Github

Java Data Types Hackerrank Solution Github
Java Data Types Hackerrank Solution Github

    Java Data Types Hackerrank Solution Github

    Java Data Types: A java Data type specifies the different sizes and values that can be stored in the variable. There are two types of data types in the Java Language. Data Type most important and useful concept. Data types are used in every programming language.


    Primitive data types in java

    Primitive data types: Primitive data types in java boolean Data Types, char Data Types, byte Data Types, short Data Types, int Data Types, long Data Types, float Data Types, and Double DataTypes.


    Non-primitive data types in java

    Non-primitive data types: A non-primitive data types include Classes, Interfaces, and Arrays. 

    Java Non-Primitive Data Types

    Classes

    Interface

    Array


    Primitive data types: Primitive data types in java boolean Data Types, char Data Types, byte Data Types, short Data Types, int Data Types, long Data Types, float Data

    Types of Primitive Data Types in Java

    1. boolean data type

    2. byte data type

    3. char data type

    4. short data type

    5. int data type

    6. long data type

    7. float data type

    8. double data type.


    Java data types default values

    Data Types

    Default Value

    Default Size

    Boolean

    /u0000 1 byte

    Char

    0 2 byte

    Byte

    0 1 byte

    Short

    0 2 byte

    Int

    0 4 byte

    Long

    0L 8 byte

    Float

    0.0f 4

    Double

    0.0d 8 byte


    Boolean data type in java

    Boolean Data Type: The Boolean knowledge kind is employed to store solely 2 potential values.True and False.

    This knowledge kind is employed for easy flags that track true/false conditions.

    The Boolean knowledge kind specifies one little bit of info, however, its "size" cannot be outlined exactly.


    Byte data type program in java

    public class BooleanExample1 

    {    

    public static void main(String[] args)

    {  

    int a=10;  

    int b=20;  

    boolean b1=true;  

    boolean b2=false;  

    if(a<b)  

    {  

    System.out.println("condition is:"+b1);  

    }  

    else  

    {  

    System.out.println("condition is:"+b2);  

    }  

    }         

    }  


    *****OUTPUT*****

    Compile by: javac BooleanExample1.java

    Run by: java BooleanExample1

    condition is: true


    Byte data type in java

    Byte data Types: A byte data type is a Java primitive data type.

    It is an 8-bit signed two's complement integer. Its value range lies between -128 to 127.

    Its minimum value is -128 and its maximum value is 127. Its default value is 0.


    Byte data type program in java

    public class ByteExample1 

    {

    public static void main(String[] args) 

    {

    byte a=-128;

    byte b=-127;

    System. out.println("Minimum Value in Byte:"+a);

    System. out.println("Maximum Value in Byte:"+b);

    }

    }


    *****OUTPUT*****

    Compile by: javac ByteExample1.java

    Run by: java ByteExample1

    Minimum Value in Byte:-128

    Maximum Value in Byte:-127


    Short data type in java

    Short Data Types: A short data type is a 16-bit signed two's complement integer.

    Its value-range lies between -32,768 to 32,767. It is minimum value is -32,768 and the maximum value is 32,767. Its default value is 0.


    Short data type program in java

    public class ShortExample1  

    public static void main(String args[]) 

    {

    short a=-10;  

    short b=10;  

    System.out.println("Minimum value in short Data Types:"+a);  

    System.out.println("Minimum value in short Data Types: "+b);  

    }

    }  


    *****OUTPUT*****

    Compile by: javac ShortExample1.java

    Run by: java ShortExample1

    The minimum value in short Data Types:-10

    The maximum value in short Data Types:10


    Integer Data Types in Java

    Int Data Types: A int data type is a 32-bit signed two complement integer value. It is value-range lies between - 2,147,483,648 to 2,147,483,647. Its minimum value is - 2,147,483,648 and maximum value is  2,147,483,647. It is default value is 0.


    Integer data type program in java 

    public class intExample1

    {  

    public static void main(String args[])  

    {  

    int a=-1000;  

    int b=1000;  

    System.out.println("Minimum value in int Data Types:"+a);  

    System.out.println("Minimum value in int Data Types: "+b);  

    }  

    }  


    *****OUTPUT*****

    Compile by: javac intExample1.java

    Run by: java intExample1

    The minimum value in int Data Types:-1000

    The maximum value in int Data Types:1000


    Long data type in java

    Long Data Type: A long data type is a 64-bit two's complement integer. Its value-range lies between -9,223,372 to 9,223,372. Its minimum value is - 9,223,372 and maximum value is 9,223,372. Its default value is 0.


    Long data type program in java

    public class LongExample1  

    {  

    public static void main(String args[])  

    {  

    Long a=-100000L;  

    Long b=100000L;  

    System.out.println("Minimum value in Long Data Types:"+a); 

    System.out.println("Minimum value in Long Data Types: "+b);  

    }  

    }  


    *****OUTPUT*****

    Compile by: javac LongExample1.java

    Run by: java LongExample1

    The minimum value in Long Data Types:-100000

    The maximum value in Long Data Types:100000


    Float data type in java

    Float Data Types: Afloat data type is a single-precision 32-bit floating point. Its value range is unlimited. It is recommended to use a float instead of a double if you need to save memory in large arrays of floating-point numbers.


    Float data type program in java

    public class FloatExample1  

    {  

    public static void main(String args[])  

    {  

    float a=64.65f;  

    System.out.println("Value of Float Data Types:"+a);  

    }  

    }  


    *****OUTPUT*****

    Compile by: javac FloatExample1.java

    Run by: java FloatExample1

    Value of Float Data Types:64.65f


    Double data type in java

    Double Data Type: The double data type is a double-precision 64-bit  floating-point. Its value range is unlimited. The double data type is generally used for decimal values just like float. It is default value is 0.0d.


    Double data type program in java

    public class DoubleExample1  

    {  

    public static void main(String args[])  

    {  

    double a=614.65d;  

    System.out.println("Value of Double Data Types:"+a);  

    }  

    }  


    *****OUTPUT*****

    Compile by: javac DoubleExample1.java

    Run by: java DoubleExample1

    Value of Double Data Types:614.65d


    Char data type in java

    Char Data Types: A char data type is a single 16-bit Unicode character. Its value- range lies between '\u0000' The char data type is used to store characters.


    Char data type program in java

    public class CharExample1  

    {  

    public static void main(String args[])  

    {  

    char gender='M';  

    System. out.println("Value of Char Data Types:"+gender);  

    }  

    }  


    *****OUTPUT*****

    Compile by: javac CharExample1.java

    Run by: java CharExample1

    Value of Char Data Types: M


    Read Also Data Types of Other Languages

    👉Python Data Types


    👉C++ Data Types


    👉C Data Types

    Post a Comment

    0 Comments
    * Please Don't Spam Here. All the Comments are Reviewed by Admin.