Java - Data types part2


Java - Data types part2

Sample Code :

import java.io.*;
public class DataTypes		{
public static void main(String[] args){
    byte a = 10;
    short b = 20;
    int c = 30;
    long d = 40;
    float e = 50.5f;
    double f = 60.5d;
    char g = 'A';
    boolean h = true;
    String i = "WikiTechy";
    System.out.println("WikiTechy - Value from different Data Types"); 	
    System.out.println(); 
    System.out.println();
    System.out.println("\n Byte Value: " + a);
    System.out.println("\n Short Value: " + b);
    System.out.println("\n Integer Value: " + c);
    System.out.println("\n Long Value: " + d);
    System.out.println("\n Float Value: " + e);
    System.out.println("\n Double Value: " + f);     System.out.println("\n Char Value: " + g);     System.out.println("\n boolean Value: " + h);     System.out.println("\n String Value: " + i); } }

Code Explanation :


    Declaring and initializing variables with the following code:

    byte a = 10;
    short b = 20;
    int c = 30;
    long d = 40;
    float e = 50.5f;
    double f = 60.5d;
    char g = 'A';
    boolean h = true;
    String i = "WikiTechy";

    Printing an empty line for neatness in output.


    Printing each value, assigned to the variable, one by one to the output window using the below code,

    System.out.println("\n Byte Value: " + a); 
    System.out.println("\n Short Value: " + b);
    System.out.println("\n Integer Value: " + c);
    System.out.println("\n Long Value: " + d);
    System.out.println("\n Float Value: " + e);
    System.out.println("\n Double Value: " + f);     System.out.println("\n Char Value: " + g);     System.out.println("\n boolean Value: " + h);     System.out.println("\n String Value: " + i);

Output :


  • Hence the java datatypes the execution has been done successfully.