Class Integer
Integers are positive and negative whole 32-bit unsigned numbers without decimals. If you need to work with decimals, use the Float data type.
Constructors
Integer(Integer)
Pass a value to copy into a new object.
Declaration
Integer Integer(Integer value)
Parameters
Type | Name | Description |
Integer | value | Integer object. |
Type | Description |
Integer |
Integer(String)
Pass a String containing a number. The constructor will parse the text and create an Integer object.
Declaration
Integer Integer(String value)
Examples
Integer favOfSheldon = Integer("73");
Parameters
Type | Name | Description |
String | value | A String containing a number. For example "13". |
Type | Description |
Integer |
Methods
toString()
Converts a numeric value to its string representation.
One of the most frequently used methods, typically when you are going to output something.Declaration
String toString()
Examples
Integer c = 100;
String s = c.toString();
Returns
Type | Description |
String |
toBool()
Converts a numeric value to its boolean representation. Returns false if the integer is zero, otherwise true.
Declaration
Bool toBool()
Examples
Integer i = 3;
printLine(i.toBool().toString());
Returns
Type | Description |
Bool |
abs()
Converts a numeric value to its absolute value (the non-negative value of the number without regarding the sign).
One of the most frequently used methods, typically when you are going to output something.Declaration
Integer abs()
Examples
Integer i = -7;
print(i.abs().toString());
Returns
Type | Description |
Integer |
toHex()
Converts an Integer to a hexadecimal string.
Declaration
String toHex()
Examples
printLine("Int \t Hex");
for (Integer i = 0; i < 16; i++) {
printLine(i.toString() +"\t " + i.toHex());
}
Returns
Type | Description |
String |
toHex(Integer)
Converts an Integer to a hexadecimal string.
Same as above except you write toHex(i) rather than i.toHex().Declaration
String toHex(Integer)
Parameters
Type | Name | Description |
Integer | value | Integer object. The value to convert to hex. |
Returns
Type | Description |
String |
isNull()
Returns true if it has no value and false if it does.
Declaration
Bool isNull()
Examples
Integer i;
printLine(i.isNull().toString());
i = 0;
printLine(i.isNull().toString());
The 1st output will be true because we haven't initialized ì yet.
The next output will be false because i now has the value 0.
Returns
Type | Description |
Bool |