0% found this document useful (0 votes)
3 views8 pages

Errors & Math Class

The document outlines different types of errors in programming, including syntax, semantic, and logical errors, as well as compile-time and runtime errors. It also describes the Math class in Java, which includes static methods for various mathematical functions such as max, min, pow, and random. Each method is detailed with its purpose, arguments, and result type.

Uploaded by

anoushkajohri
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views8 pages

Errors & Math Class

The document outlines different types of errors in programming, including syntax, semantic, and logical errors, as well as compile-time and runtime errors. It also describes the Math class in Java, which includes static methods for various mathematical functions such as max, min, pow, and random. Each method is detailed with its purpose, arguments, and result type.

Uploaded by

anoushkajohri
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

-Types of errors

-Math class
Types of Errors
• Syntax errors : These errors occur when the syntax of the language is not respected.
e.g int a=5 //error-semi colon is missing
y=(3+9 ; //closing parenthesis is missing
• Semantic errors : These are the errors due to an improper use of statements
x*y=z; //syntactically correct but semantically incorrect ;
expression cannot be on left hand side of an assignment statement
1. Static semantic errors : Caught by the compiler
e.g int a; //variable not initialised
a++;
int a =“hello” ; //type mismatch
2. Dynamic semantic errors : the errors not caught by the compiler and caught
during the runtime.
int [ ] v = new int [10];
v[10] =100; // array out of bounds
Types of Errors
• Logical errors : A logical error is that error that causes a program to produce
incorrect or undesired output.
e.g int a=1 ;
while(a<=10) //infinite loop
{
[Link](“hello”);
}
Errors from the point of view of phase of error detection
• Compile time errors : Errors detected during the compilation phase
e.g syntax and static semantic errors
• Runtime errors : Errors detected during the execution (runtime) phase e.g
dynamic semantic errors and logical errors.
The Math Class

• The Math class is part of the [Link] package

• The Math class contains methods that perform various mathematical functions
such as square root , cube root, absolute value etc.
The Math Class

• The methods of the Math class are static methods (also called class methods)

• Static methods can be invoked through the class name – No object of the
Math class is needed
double value = [Link](25.0);
Math Methods
Method Purpose Argument Result Type

max(x,y) Returns the larger of x int , double ,float same as argument


and y or long
min(x,y) Returns the smaller of x int , double ,float same as argument
and y or long
pow(x,y) Returns xy. double double

random() Returns a random Requires no double


number greater than or arguments
equal to 0.0 and less
than 1.0
Math Methods
Method Purpose Argument Result Type

abs(x) Returns the absolute int , double ,float or same as argument


value of x long

ceil(x) Returns the closest double double


number >= x

floor(x) Returns the closest double double


number <= x
Math Methods

Method Purpose Argument Result Type


round(x) Returns the integer double or float long or int
rounded to the nearest
whole number
sqrt(x) Returns the square root double double
of x

cbrt(x) Returns the cube root of double double


x

You might also like