In Java, numbers are an important data type that is used to represent numeric values. There are several types of numbers in Java, including integers, floating-point numbers, and complex numbers.
Integers:
Integers are whole numbers that can be positive, negative, or zero. Java provides several types of integer variables, including byte, short, int, and long. The sizes are:
● byte: 8-bit signed integer (-128 to 127)
● short: 16-bit signed integer (-32768 to 32767)
● int: 32-bit signed integer (-2147483648 to 2147483647)
● long: 64-bit signed integer (-9223372036854775808 to 9223372036854775807)
Example:
byte b = 100;
short s = 20000;
int i = 1000000000;
long l = 1000000000000000000L;
Floating-Point Numbers
Floating-point numbers are numbers that have a decimal point. The two types of floating point numbers in java are:
● float: 32-bit single-precision floating-point number
● double: 64-bit double-precision floating-point number
Example:
float f = 3.14f;
double d = 3.14;
Java also provides a class called BigDecimal, which can be used to represent arbitrary-precision decimal numbers.
BigDecimal bd = new BigDecimal("3.14");
Java also provides several built-in functions, such as Math. abs(), Math. ceil(), Math. floor(), Math. round() and Math. max(), Math. min(), Math. sqrt() etc.