Initial commit

This commit is contained in:
toly
2023-04-16 10:28:45 +08:00
commit a1465d4a52
139 changed files with 5073 additions and 0 deletions

149
test/grammer/base.dart Normal file
View File

@@ -0,0 +1,149 @@
void main() {
// ---->[break情景]----
for (int i = 0; i < 10; i++) {
if (i % 3 == 2) {
break; //直接跳出循环
}
print("i:$i"); //打印了01
}
// ---->[continue情景]----
for (int i = 0; i < 10; i++) {
if (i % 3 == 2) {
continue; //跳出本次循环,将进入下次循环
}
print("i:$i"); //打印了 0134679
}
}
void main13() {
int sum = 0;
int i = 0;
do {
sum += i;
print("$i 次执行,sum = $sum");
i = i + 1;
} while (i < 5);
}
void main12() {
int sum = 0;
int i = 0;
while (i < 5) {
sum += i;
print("$i 次执行,sum = $sum");
i = i + 1;
}
}
void main11() {
int sum = 0;
for (int i = 0; i < 5; i = i + 1) {
sum += i;
print("$i 次执行,sum = $sum");
}
}
void main10() {
String mark = 'A';
switch (mark) {
case 'A':
print("优秀");
break;
case 'B':
print("良好");
break;
case 'C':
print("普通");
break;
case 'D':
print("较差");
break;
case 'E':
print("极差");
break;
default:
print("未知等级");
}
}
void main9() {
double height = 1.18;
// 布尔值可以通过运算获得
bool free = height < 1.2;
if (free) {
print("可免费入园");
} else {
print("请购买门票");
}
}
// 逻辑运算符
void main8() {
// 公园是否开放
bool open = true;
// 公园是否开放
bool free = false;
// 公园是否免费开放
bool freeEnter = open && free;
}
// 算术运算符
void main7() {
print(1 > 2); //false 大于
print(1 < 2); //true 小于
print(1 == 2); //false 等于
print(1 != 2); //true 不等
print(10 >= 3); //true 大于等于
print(10 <= 3); //false 小于等于
}
// 比较运算符
void main6() {
print(1 + 2); //3 加
print(1 - 2); //-1 减
print(1 * 2); //2 乘
print(1 / 2); //0.5 除
print(10 % 3); //1 余
print(10 ~/ 3); //3 商
}
void main5() {
// 直接赋值
bool enable = true;
double height = 1.18;
// 布尔值可以通过运算获得
bool free = height < 1.2;
}
void main4() {
double a = 2.3;
double b = 4.5;
double c = 2.5;
double avg = (a + b + c) / 3;
String output = '$a,$b,$c 的平均值是$avg';
// String output = '$a,$b,$c 的平均值是${(a + b + c) / 3}';
print(output);
}
void main3() {
String hello1 = 'Hello, World!';
String hello2 = "Hello, Flutter!";
print(hello1 + hello2);
}
void main0() {
int age = 2;
double weight = 4.5;
}
void main1() {
double a = 2.3;
double b = 4.5;
double c = 2.5;
double avg = (a + b + c) / 3;
print(avg);
}

View File

@@ -0,0 +1,20 @@
void main() {
double toly = bmi(1.8, 70);
double ls = bmi(1.79, 65);
double wy = bmi(1.69, 50);
print("===toly:$toly===ls:$ls===wy:$wy===");
}
// void main() {
// double toly = 1.8 / (70 * 70);
// double ls = 1.79 / (65 * 65);
// double wy = 1.69 / (50 * 50);
// print("===toly:$toly===ls:$ls===wy:$wy===");
// }
double bmi(double height, double wight) {
// 具体算法
double result = wight / (height * height);
return result;
}

View File

@@ -0,0 +1,23 @@
void main() {
double toly = bmi(weight: 70, height: 1.8);
double ls = bmi(height: 1.79);
double wy = bmi(height: 1.69, weight: 50);
print("===toly:$toly===ls:$ls===wy:$wy===");
}
// void main() {
// double toly = 1.8 / (70 * 70);
// double ls = 1.79 / (65 * 65);
// double wy = 1.69 / (50 * 50);
// print("===toly:$toly===ls:$ls===wy:$wy===");
// }
double bmi({
required double height,
double weight = 65,
}) {
// 具体算法
double result = weight / (height * height);
return result;
}

View File

@@ -0,0 +1,20 @@
void main() {
double toly = bmi(70, 1.8);
double ls = bmi();
double wy = bmi(1.69);
print("===toly:$toly===ls:$ls===wy:$wy===");
}
// void main() {
// double toly = 1.8 / (70 * 70);
// double ls = 1.79 / (65 * 65);
// double wy = 1.69 / (50 * 50);
// print("===toly:$toly===ls:$ls===wy:$wy===");
// }
double bmi([double height = 1.79, double weight = 65]) {
// 具体算法
double result = weight / (height * height);
return result;
}

14
test/grammer/oop/01.dart Normal file
View File

@@ -0,0 +1,14 @@
class Human {
String name = '';
double weight = 0;
double height = 0;
}
void main(){
Human toly = Human();
toly.name = "捷特";
toly.weight = 70;
toly.height = 180;
print("Human: name{${toly.name},weight:${toly.weight}kg,height:${toly.height}cm}");
}

12
test/grammer/oop/02.dart Normal file
View File

@@ -0,0 +1,12 @@
class Human {
String name = '';
double weight = 0;
double height = 0;
Human(this.name,this.weight,this.height);
}
void main(){
Human toly = Human("捷特",70,180);
print("Human: name{${toly.name},weight:${toly.weight}kg,height:${toly.height}cm}");
}

52
test/grammer/oop/03.dart Normal file
View File

@@ -0,0 +1,52 @@
class Human {
String name = '';
double weight = 0;
double height = 0;
Human(this.name, this.weight, this.height);
String info() {
return "Human: name{${name},weight:${weight}kg,height:${height}cm}";
}
}
void main() {
Human toly = Human("捷特", 70, 180);
print(toly.info());
Human ls = Human("龙少", 65, 179);
print(ls.info());
Human wy = Human("巫缨", 65, 179);
print(wy.info());
}

40
test/grammer/oop/04.dart Normal file
View File

@@ -0,0 +1,40 @@
class Human {
String name = '';
double weight = 0;
double height = 0;
Human(this.name, this.weight, this.height);
double bmi() {
double result = weight / ((height/100) * (height/100));
return result;
}
String info() {
return "Human: name{${name},weight:${weight}kg,height:${height}cm}";
}
}
class Student extends Human {
final String school;
Student(
super.name,
super.weight,
super.height, {
required this.school,
});
@override
String info() {
String info = super.info() + "school: $school ";
return info;
}
}
void main() {
Student toly = Student("捷特", 70, 180,school: "安徽建筑大学");
print(toly.bmi());
print(toly.info());
}