Programming Tutorials

Program using concept of byte long short and int in java

By: Java Samples in Java Tutorials on 2017-12-10  

This simple java program describes how to use the different data types byte, short, int and long in Java.

public class DataTypes {

    byte a = 50;
    byte b = (byte) -80;
    short c = 1000;
    short d = -1500;
    int e = -15000;
    int f = 20000;
    long g = -1000L;
    long h = 2000L;

    byte addb() {

        return (byte) (a + b);

    }

    short adds() {

        return (short) (c + d);

    }

    int addi() {

        return e + f;

    }

    long addl() {

        return g + h;

    }
}

class MainClass {

    public static void main(String args[]) {

        DataTypes obj = new DataTypes();

        System.out.println("The byte Value is : " + obj.addb());
        System.out.println("The short Value is : " + obj.adds());
        System.out.println("The int Value is : " + obj.addi());
        System.out.println("The long Value is : " + obj.addl());
    }
}






Add Comment

* Required information
1000

Comments

No comments yet. Be the first!

Most Viewed Articles (in Java )

Latest Articles (in Java)