Using Numeric Types

Practise your skills and try to change the code. Read the comments and try what is within the TODO comment.

class NumericsDemo {
    public static void main (String[] args) {
        //The numeric types store numbers without decimal places
        //The byte store values in the range from -128 to 127
        byte maximumUsersPerGroup = 120;
        System.out.println("byte " + maximumUsersPerGroup);
        //Try changing the value of maximumUsersPerGroup to 128 and Run again

        //short type stores values in the range from -32768 to 32767
        short maximumMessageLength = 5000;
        System.out.println("short " + maximumMessageLength);

        //The Java compiler is optimized to use the int type
        //This should be your default choice when you need a number
        //That is within the range -2147483648 to 2147483647
        int currentUsersOnline = 9300;

        //Use the long type for storing numbers greater than the int type
        //It can store values in the range -9.22337203685478E18 to 9.22337203685478E18
        //This is a huge number
        long maximumCharacters = 140;
        //You will need to add the L suffix for any numbers greater that the int maximum
        long maximumPhotoSize = 68719476736L;
        System.out.println("long " + maximumPhotoSize);

        //The char data type is represented internally as a number
        //It holds a single unicode character
        char correctAnserOption = 'A';
        //The unicode value for the @ sign is 64.
        char atSign = 64;


results matching ""

    No results matching ""