Datatypes:
Dart is a statically-typed, object-oriented programming language used for building scalable and high-performance web, desktop, and mobile applications. It supports several data types, including:
1.Numbers: Dart supports both integers and floating-point numbers (double).
Example:
void main(){
int a=20;
}
output:
The sum is : 23.5
Dart programing
2.Strings: Strings are used to represent sequences of characters, and can be declared using single or double quotes.
Example:
void main(){
//strings
{pro1: java, pro2: dart, pro3: c, pro4: python}
dart
Operators in Dart Program:
Dart, like many programming languages, uses operators to perform operations on variables and values. Operators are symbols that tell the compiler to perform specific operations and return the result.
1.Arithmetic operators: +, -, *, /, %, and others. These operators are used to perform basic arithmetic operations, such as addition, subtraction, multiplication, division, and modulo.
Example:
void main(){
// operators
int a=2;
int b=3;
print("The sum is : ${a+b}");
print('The sub is : ${a-b}');
print("The mul is : ${a*b}");
print("The div is : ${a/b}");
}
output:
The sum is : 5
The sub is : -1
The mul is : 6
The div is : 0.6666666666666666
2.Relational operators: ==, !=, >, <, >=, <=. These operators are used to compare values and return a Boolean result (true or false). For example, 5 == 5 returns true, while 5 == 6 returns false.
Example:
void main(){
//Relational operators
var a=20;
var b=10;
print("a is greater than b : ${a>b}");
print("a is less than b : ${a<b}");
print("a is greater than or equal to b : ${a>=b}");
print("a is less than or equal to b : ${a<=b}");
print("a is equal to b : ${a==b}");
print("a is not equal to b : ${a!=b}");
}
output:
a is greater than b : true
a is less than b : false
a is greater than or equal to b : true
a is less than or equal to b : false
a is equal to b : false
a is not equal to b : true
3.Type test operators:
Example:
void main(){
//type test operators
String a="techxplore";
var b=20;
print(a is String);
print(b is !int);
}
output:
true
false
4.Logical operators: &&, ||, !. These operators are used to perform logical operations and return a Boolean result. For example, true && false returns false, while true || falsereturns true.
Example:
void main(){
//logical operators
int a=10;
int b=20;
bool c=a>b && a<b;
bool d=a>b || a<b;
print(c);
print(d);
}
output:
false
true
5.Assignment operator: =. This operator is used to assign a value to a variable. For example, x = 5; assigns the value 5 to the variable x.
No comments:
Post a Comment