Collections and Important Libraries

Agenda

  •  

  • Product Design

  • Development

  • UI/UX Testing

  • Branding

The Java Math module provides the users with various methods relating to maths.

Math module

Comparisons

class Main {
    public static void main(String[] args) {
        int a = Math.max(3, 5);
        int b = Math.min(3, 5);

        System.out.println(a);  // 5
        System.out.println(b);  // 3
    }
}

Rounding off

class Main {
    public static void main(String[] args) {
        double x = Math.floor(3.2);
        double y = Math.ceil(3.2);
        double z = Math.round(3.2);
        double a = Math.round(3.8);

        System.out.println(x);  // 3.0
        System.out.println(y);  // 4.0
        System.out.println(z);  // 3.0
        System.out.println(a);  // 4.0
    }
}

Logarithms and Exponents

class Main {
    public static void main(String[] args) {
        double E = Math.E;
        System.out.println(E);  // 2.718281828459045
        double x = Math.log(E);
        double y = Math.log10(100);

        System.out.println(x);   // 1.0
        System.out.println(y);   // 2.0

        double a = Math.pow(2, 3);
        System.out.println(a);   // 8.0

        double b = Math.sqrt(25);
        System.out.println(b);  // 5.0
    }
}

Trigonometry

class Main {
    public static void main(String[] args) {
        final double PI = Math.PI;
        System.out.println(PI);

        System.out.println(Math.sin(PI / 6));
        System.out.println(Math.sin(0));

        System.out.println(Math.cos(PI / 3));
        System.out.println(Math.cos(0));
    }
}

The BigInteger class is used to store and work with large integer values.

BigInteger

class Main {
    public static void main(String[] args) {
        BigInteger a = new BigInteger("200000000000000000000000000");
        BigInteger b = new BigInteger("300000000000000000000000000");
        
        BigInteger c = a.add(b);
        System.out.println(c);  // 500000000000000000000000000
    }
}

Compute Factorial

Given an integer N, compute its factorial.

 

Sample Input

N = 5

 

Sample Output

120

Collections & Utility Libraries

By Tarun Luthra

Collections & Utility Libraries

  • 30