integer range in java code example
Example 1: random number in range java
(int)(Math.random() * ((max - min) + 1)) + min
Copy
Example 2: java max int value
public class Test
{
public static void main(String[] args)
{
System.out.println(Integer.MIN_VALUE);
System.out.println(Integer.MAX_VALUE);
System.out.println(Integer.MIN_VALUE - 1);
System.out.println(Integer.MAX_VALUE + 1);
}
}
Example 3: range of int
TypeName Bytes Range of Values
int 4 -2,147,483,648 to 2,147,483,647
Example 4: java long literal
to declare a Long literal in java, add 'L' to the end of
an integer literal
examples:
12312345514316L
59741316635446100055330L
465414966143L