Dart BigInt isOdd
Syntax & Examples
BigInt.isOdd property
The `isOdd` property checks whether a given big integer is odd.
Syntax of BigInt.isOdd
The syntax of BigInt.isOdd property is:
bool isOdd
This isOdd property of BigInt whether this big integer is odd.
Return Type
BigInt.isOdd returns value of type bool
.
✐ Examples
1 Check Oddness of Positive and Negative Numbers
In this example,
- We create two BigInt objects,
num1
andnum2
, initialized with 10 and 15 respectively. - We then use the
isOdd
property to check if these numbers are odd. - We print the results to standard output.
Dart Program
void main() {
BigInt num1 = BigInt.from(10);
BigInt num2 = BigInt.from(15);
bool isOdd1 = num1.isOdd;
bool isOdd2 = num2.isOdd;
print('10 is odd: $isOdd1');
print('15 is odd: $isOdd2');
}
Output
10 is odd: false 15 is odd: true
2 Check Oddness of a Negative Number
In this example,
- We create a BigInt object,
num
, initialized with -7. - We then use the
isOdd
property to check if this number is odd. - We print the result to standard output.
Dart Program
void main() {
BigInt num = BigInt.from(-7);
bool isOdd = num.isOdd;
print('-7 is odd: $isOdd');
}
Output
-7 is odd: true
3 Check Oddness of a Large Number
In this example,
- We create a BigInt object,
num
, by parsing the string '123456789012345678901234567890'. - We then use the
isOdd
property to check if this large number is odd. - We print the result to standard output.
Dart Program
void main() {
BigInt num = BigInt.parse('123456789012345678901234567890');
bool isOdd = num.isOdd;
print('Large number is odd: $isOdd');
}
Output
Large number is odd: true
Summary
In this Dart tutorial, we learned about isOdd property of BigInt: the syntax and few working examples with output and detailed explanation for each example.