Java

Integer, max

Console

import java.lang.Math;
public class Program {
public static void main(String[] args) {
*// These are all reduced, even the negative number.*
double floor1 = **Math.floor**(*1.9*);
double floor2 = Math.floor(*1.1*);
double floor3 = Math.floor(*-1.3*);
System.out.println(floor1);
System.out.println(floor2);
System.out.println(floor3);
}
}1.0
1.0
-2.0

public class Program {
public static void main(String[] args) {
*// Use Math.floorDiv to compute the floor of a division.*
*// ... The first argument is the number being divided.*
*// ... The second argument is the divisor.*
int result = **Math.floorDiv**(9, 2);
System.out.println(result);
*// This is the same division with no floor.*
double result2 = (double) 9 / 2;
System.out.println(result2);
}
}4
4.5

public class Program {
public static void main(String[] args) {
*// The remainder of 10 modulo 6 is 4.*
int result = **Math.floorMod**(10, 6);
int result2 = 10 % 6;
System.out.println(result);
System.out.println(result2);
*// Use negative numbers mixed with positive numbers.*
*// ... These are different with floorMod.*
int result3 = **Math.floorMod**(10, -6);
int result4 = 10 % -6;
System.out.println(result3);
System.out.println(result4);
}
}4
4
-2
4

Math.ceil

Dot Net Perls is a collection of tested code examples. Pages are continually updated to stay current, with code correctness a top priority.

Sam Allen is passionate about computer languages. In the past, his work has been recommended by Apple and Microsoft and he has studied computers at a selective university in the United States.

This page was last updated on Aug 6, 2021 (edit).