Java

Numbers in Java

Numbers in Java

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. 
 

Top course recommendations for you

    Python IDLE
    1 hrs
    Beginner
    1.5K+ Learners
    4.71  (21)
    Python vs R
    3 hrs
    Beginner
    1.5K+ Learners
    4.57  (46)
    Highest Paying Tech Jobs
    1 hrs
    Beginner
    2.7K+ Learners
    4.09  (11)
    Threading and Scheduling in Python
    2 hrs
    Beginner
    1.7K+ Learners
    4.58  (38)
    Beautiful Soup
    2 hrs
    Beginner
    1.3K+ Learners
    4.59  (49)
    Java Applications
    1 hrs
    Beginner
    6K+ Learners
    4.47  (125)
    Python List
    1 hrs
    Beginner
    4.3K+ Learners
    4.6  (145)
    Python Classes
    1 hrs
    Beginner
    5.9K+ Learners
    4.51  (166)
    OOPs in Python
    1 hrs
    Beginner
    13.2K+ Learners
    4.39  (752)
    Python Careers
    1 hrs
    Beginner
    5.3K+ Learners
    4.4  (48)