Professional Documents
Culture Documents
Public Class Findabsolutevalueexample (
Public Class Findabsolutevalueexample (
int i = 8;
int j = -5;
/*
*
* It returns the same value if the agrument is non negative value, otherwise
*
*/
float f1 = 10.40f;
float f2 = -50.28f;
/*
*
* It returns the same value if the agrument is non negative value, otherwise
*
*/
double d1 = 43.324;
double d2 = -349.324;
/*
*
* It returns the same value if the agrument is non negative value, otherwise
*
*/
long l1 = 34;
long l2 = -439;
/*
*
* It returns the same value if the agrument is non negative value, otherwise
* negation of the negative value.
*
*/
/*
Output would be
Absolute value of 8 is :8
Absolute value of -5 is :5
*/
public class FindCeilingExample {
/*
*
* It returns a smallest integer which is not less than the argument value.
*/
System.out.println(Math.ceil(10));
System.out.println(Math.ceil(10.1));
System.out.println(Math.ceil(5.5));
System.out.println(Math.ceil(-20));
System.out.println(Math.ceil(-42.4));
//returns 0
System.out.println(Math.ceil(0));
/*
Output would be
10.0
11.0
6.0
-20.0
-42.0
0.0
*/
public class FindExponentialNumberExample {
/*
*
*/
/*
Output would be
Exponential of 2 is : 7.38905609893065
*/
public class FindFloorValueExample {
/*
*
* It returns a largest integer which is not grater than the argument value.
*/
System.out.println(Math.floor(70));
System.out.println(Math.floor(30.1));
System.out.println(Math.floor(15.5));
System.out.println(Math.floor(-40));
System.out.println(Math.floor(-42.4));
//returns 0
System.out.println(Math.floor(0));
/*
Output would be
70.0
30.0
15.0
-40.0
-43.0
0.0
*/
public class FindMaxOfTwoNumbersExample {
/*
*/
System.out.println(Math.max(20,40));
/*
*/
System.out.println(Math.max(324.34f,432.324f));
/*
*/
System.out.println(Math.max(65.34,123.45));
/*
*/
System.out.println(Math.max(435l,523l));
/*
Output would be
40
432.324
123.45
523
public class FindMinimumOfTwoNumbersExample {
/*
*/
System.out.println(Math.min(34,45));
/*
*/
System.out.println(Math.min(43.34f, 23.34f));
/*
*/
System.out.println(Math.min(4324.334, 3987.342));
/*
*/
System.out.println(Math.min(48092840,4230843));
/*
Output would be
34
23.34
3987.342
4230843
*/
public class FindNaturalLogarithmOfNumberExample {
/*
*/
/*
Output would be
/*
* static double pow(double d1, double d2) method of Java Math class.
*/
System.out.println(Math.pow(2,2));
System.out.println(Math.pow(-3,2));
/*
Output would be
4.0
9.0
*/
public class FindSquareRootExample {
/*
*/
System.out.println(Math.sqrt(9));
System.out.println(Math.sqrt(25.5));
/*
Output would be
3.0
5.049752469181039
*/
public class GenerateRandomIntByRange {
/*
Example :
*/
System.out.println(random);
}
public class GenerateRandomNumbers {
/*
*
*/
/*
*/
/*
*/
public class RounFloatDoubleNumbersExample {
/*
*
* Internally, it adds 0.5 to the argument, takes floor value and casts
*
*/
System.out.println(Math.round(10f));
System.out.println(Math.round(20.5f));
System.out.println(Math.round(20.5f));
System.out.println(Math.round(-19.4f));
//returns (int) Math.floor(-23) = -23
System.out.println(Math.round(-23.5f));
/*
* It returns long.
*/
/*
Output would be
10
21
21
-19
-23
*/