(Prac 1)Program to demonstrate the features of Dart language.
Convert String To Int In dart
void main() {
String strvalue = "1";
print("Type of strvalue is ${strvalue.runtimeType}");
int intvalue = int.parse(strvalue);
print("Value of intvalue is $intvalue");
// this will print data type
print("Type of intvalue is ${intvalue.runtimeType}");
}
Convert String To Double In Dart
void main() {
String strvalue = "1.1";
print("Type of strvalue is ${strvalue.runtimeType}");
double doublevalue = double.parse(strvalue);
print("Value of doublevalue is $doublevalue");
// this will print data type
print("Type of doublevalue is ${doublevalue.runtimeType}");
}
Convert Int To String In Dart
void main() {
int one = 1;
print("Type of one is ${one.runtimeType}");
String oneInString = one.toString();
print("Value of oneInString is $oneInString");
// this will print data type
print("Type of oneInString is ${oneInString.runtimeType}");
}
Convert Double To Int In Dart
void main() {
double num1 = 10.01;
int num2 = num1.toInt(); // converting double to int
print("The value of num1 is $num1. Its type is ${num1.runtimeType}");
print("The value of num2 is $num2. Its type is ${num2.runtimeType}");
}
To Print 1 To 10 Using For Loop
void main() {
for (int i = 1; i <= 10; i++) {
print(i);
}
}
Below code prints the even numbers from 1 to 10.
void main() {
for( var i = 1 ; i <= 10; i++ ) {
if(i%2==0) {
print(i);
}
}
}
Functions
void main() {
add(3,4);
}
void add(int a,int b) {
int c;
c = a+b;
print(c);
return c;
}
Comments
Post a Comment