当前位置: 首页 > news >正文

日撸 Java 三百行day1-10

文章目录

    • 说明
    • day1 环境搭建
      • 1.1 开发环境
      • 1.2 package import 和 println
      • 1.3 编写HelloWorld.java
    • day2 基本算术操作
      • 2.1 加、减、乘、除、整除、取余.
    • day3 基本if 语句
      • 3.1 if条件分支语句
      • 3.2 代码
    • day4 闰年的计算
      • 4.1 思路整理:何为闰年?
      • 4.2 核心代码
    • day5 基本switch 语句
      • 5.1 switch也属于条件分支语句
      • 5.2 思考
    • day6 基本for 语句
      • 6.1 for语句中表达式的执行顺序
      • 6.2 代码
    • day7 矩阵元素相加
      • 7.1 题目解读
      • 7.2 二维数组中
    • day8 矩阵相乘
      • 8.1 题目解读
      • 8.2代码
    • day9 while 语句
      • 代码
    • day10 综合任务 1
      • 10.1 题目解读
      • 10.2 代码
    • 自我小结
      • 三大结构

说明

闵老师的文章链接: 日撸 Java 三百行(总述)_minfanphd的博客-CSDN博客

自己也把手敲的代码放在了github上维护:https://github.com/fulisha-ok/sampledata

day1 环境搭建

1.1 开发环境

在搭建java环境时,从官网下载了java安装包安装成功后,一定要正确配置环境变量

1.2 package import 和 println

(1)package包:就好似我们日常生活中的”收纳盒“,不同的”收纳盒“装不同的”物品“,方便我们查找和定位。在大”收纳盒“中有包含各种小”收纳盒“,这也体现了包是以树形结构存储的。

package com //一个主包
package com.project //主包下建一个项目工程包
package com.project.util //一个工具包,util工具包在com目录下的project目录中

(2)import:导入包成员,在写一个java类时,我们需用到其他包中的成员,此时就需要通过import导入相应的包,则就好似c语言需要导入头文件,才能用一些库里的函数

import java.util.ArrayList;; //导入Java util包下的ArrayList 那则可以用这个类中一些方法,变量
import java.util.*; //导入util包下所有的东西,那我们使用的范围就比上面这个更多

(3)println:打印输出语句,且在输出后会自动换行,若不换行则是print

1.3 编写HelloWorld.java

main函数是程序入口

package basic;
public class HellowWorld {public static void main(String[] args) {System.out.println("Hello, World");}
}

day2 基本算术操作

2.1 加、减、乘、除、整除、取余.

package basic;public class BasicOperations {public static void main(String args[]) {int tempFirstInt, tempSecondInt, tempResultInt;double tempFirstDouble, tempSecondDouble, tempResultDouble;tempFirstInt = 15;tempSecondInt = 4;tempFirstDouble = 1.2;tempSecondDouble = 3.5;//AdditiontempResultInt = tempFirstInt + tempSecondInt;tempResultDouble = tempFirstDouble + tempSecondDouble;System.out.println("" + tempFirstInt + " + " + tempSecondInt + " = " + tempResultInt);System.out.println("" + tempFirstDouble + " + " + tempSecondDouble + " = " + tempResultDouble);//SubtractiontempResultInt = tempFirstInt - tempSecondInt;tempResultDouble = tempFirstDouble - tempSecondDouble;System.out.println("" + tempFirstInt + " - " + tempSecondInt + " = " + tempResultInt);System.out.println("" + tempFirstDouble + " - " + tempSecondDouble + " = " + tempResultDouble);//MultiplicationtempResultInt = tempFirstInt * tempSecondInt;tempResultDouble = tempFirstDouble * tempSecondDouble;System.out.println("" + tempFirstInt + " * " + tempSecondInt + " = " + tempResultInt);System.out.println("" + tempFirstDouble + " * " + tempSecondDouble + " = " + tempResultDouble);//DivisiontempResultInt = tempFirstInt / tempSecondInt;tempResultDouble = tempFirstDouble / tempSecondDouble;System.out.println("" + tempFirstInt + " / " + tempSecondInt + " = " + tempResultInt);System.out.println("" + tempFirstDouble + " / " + tempSecondDouble + " = " + tempResultDouble);//ModulustempResultInt = tempFirstInt % tempSecondInt;System.out.println("" + tempFirstInt + " % " + tempSecondInt + " = " + tempResultInt);}
}

在这里插入图片描述

day3 基本if 语句

3.1 if条件分支语句

其中,if中的表达式应该为布尔表达式。这里会存在三种不同选择。(假设在if中会有数据的处理)

第一,只使用if语句,这相当于我只过滤我想要的数据;

第二:if…else 语句,(不入if就进else, 非真即假)

第三:if…else if…else 语句,这就是多条件分支判断。对不同条件进行判断

3.2 代码

package basic;public class IfStatement {/*** The entrance of the program* @param args*/public static void main(String args[]) {int tempNumber1, tempNumber2;// Try a positive valuetempNumber1 = 5;if (tempNumber1 >= 0) {tempNumber2 = tempNumber1;} else {tempNumber2 = -tempNumber1;} // Of ifSystem.out.println("The absolute value of " + tempNumber1 + " is " + tempNumber2);// Try a negative value// Lines 27 through 33 are the same as Lines 15 through 19tempNumber1 = -3;if (tempNumber1 >= 0) {tempNumber2 = tempNumber1;} else {tempNumber2 = -tempNumber1;} // Of ifSystem.out.println("The absolute value of " + tempNumber1 + " is " + tempNumber2);// Now we use a method/function for this purpose.tempNumber1 = 6;System.out.println("The absolute value of " + tempNumber1 + " is " + abs(tempNumber1));tempNumber1 = -8;System.out.println("The absolute value of " + tempNumber1 + " is " + abs(tempNumber1));}/*** @param paraValue The given value.* @return  The absolute value of the given parameter.*/public static int abs(int paraValue) {if (paraValue >= 0) {return paraValue;} else {return -paraValue;}}
}

在这里插入图片描述

day4 闰年的计算

4.1 思路整理:何为闰年?

(1)非世纪年(不能被100整除的年份)能被4整除且不能被100整除的年份为闰年
(2)世纪年 能被400整除的才是闰年
文中给出两种计算闰年的方法,结合day3的if语句,第一种把所有逻辑判断放在一个if中完成,会使用一些与或非逻辑运算,如果逻辑判断条件过多,如果放在一个if判断中则会增加代码的可维护性,但第二种方法是一个条件一个条件判断,如果其中有一个不满足就退出,这样是根据if-else if顺序执行,来判断只有有不符合条件就退出、

4.2 核心代码

 /*** @param paraYear* @return Is the given year leap? true or false;*/public static boolean isLeapYear(int paraYear) {if ((paraYear % 4 == 0) && (paraYear % 100 != 0) || (paraYear % 400 == 0)) {return true;} else {return false;}}/*** @param paraYear* @return Is the given year leap? Replace the complex condition with a number of if. return true or false*/public static boolean isLeapYearV2(int paraYear) {if (paraYear % 4 != 0) {return false;} else if (paraYear % 400 == 0) {return true;} else if (paraYear % 100 == 0) {return false;} else {return true;}}

day5 基本switch 语句

5.1 switch也属于条件分支语句

switch中表达式的值去和case后的值做匹配,若匹配正确则执行其后需要执行代码,遇到break结束执行。若没有case匹配,则最后就会执行default,default 分支不需要 break 语句

5.2 思考

(1)每一个case后都要跟break吗?
答案是否定的。不加break的话将会跳转到相应的case去执行且其以下的所有语句。
(2)switch和if条件语句有什么区别呢?
最明显差异是表示执行的结构,if中的表达式结果只能是boolean类型,而switch恰恰相反,他表示式结果可以是int,char等。我在实际使用过程中if语句用的比较多,但涉及到判断的if分支较多时,我会考率使用switch,这样效率会高一点

day6 基本for 语句

6.1 for语句中表达式的执行顺序

for(a;b;c)其中a,b,c为表达式,执行顺序:先执行a表达式,一般为初始化语句,再执行b表达式,一般式判断表达式,若为ture去执行循环体,执行完再执行c表达式,若不满足b表达式,则跳出循环。

6.2 代码

package basic;
public class ForStatement {/*** The entrance of the program.* @param args*/public static void main(String[] args) {forStatementTest();}/*** Method unit test.*/public static void forStatementTest(){int tempN = 0;System.out.println("1 add to " + tempN + " is: " + addToN(tempN));tempN = 0;System.out.println("1 add to " + tempN + " is: " + addToN(tempN));int tempStepLength = 1;tempN = 10;System.out.println("1 add to " + tempN + " with step length " + tempStepLength + " is: "+ addToNWithStepLength(tempN, tempStepLength));tempStepLength = 2;System.out.println("1 add to " + tempN + " with step length " + tempStepLength + " is: "+ addToNWithStepLength(tempN, tempStepLength));}/*** Add from 1 to N.* @param paraN The given upper bound.* @return The sum.*/public static int addToN(int paraN) {int resultSum = 0;for (int i = 1; i <= paraN; i++) {resultSum += i;}return resultSum;}/*** Add from 1 to N with a step length.* @param paraN The given upper bound.* @param paraStepLength paraStepLength The given step length.* @return The sum.*/public static int addToNWithStepLength(int paraN, int paraStepLength) {int resultSum = 0;for (int i = 1; i <= paraN; i += paraStepLength) {resultSum += i;}return resultSum;}
}

day7 矩阵元素相加

7.1 题目解读

矩阵用二维数组存储,计算二维数组的和,计算两个二维数组对应行列相加组成一个新的二维数组,都需要用到for循环遍历(行优先);对矩阵的赋值也需要循环遍历赋初值,在有循环时要避免死循环,确保循环是有限性的。

7.2 二维数组中

int[][] tempMatrix = new int[3][4];
tempMatrix.length; //代表行的长度
tempMatrix[0].length; //代表列的长度

代码:

package basic;import java.util.Arrays;
public class MatrixAddition {public static void main(String[] args) {matrixElementSumTest();matrixAdditionTest();}/*** Sum the elements of a matrix.* @param paraMatrix* @return  The sum of all its elements.*/public static int matrixElementSum(int[][] paraMatrix) {int resultSum = 0;for (int i = 0; i < paraMatrix.length; i++) {for (int j = 0; j < paraMatrix[0].length; j++) {resultSum += paraMatrix[i][j];}}return resultSum;}/*** Unit test for respective method*/public static void matrixElementSumTest() {int[][] tempMatrix = new int[3][4];for (int i = 0; i < tempMatrix.length; i++) {for (int j = 0; j < tempMatrix[0].length; j++) {tempMatrix[i][j] = i * 10 + j;}}System.out.println("The matrix is: \r\n" + Arrays.deepToString(tempMatrix));System.out.println("The matrix element sum is: " + matrixElementSum(tempMatrix) + "\r\n");}/*** Add two matrices. Attention: NO error check is provided at this moment.* @param paraMatrix1 The first matrix.* @param paraMatrix2 The second matrix. It should have the same size as the first one's* @return The addition of these matrices.*/public static int[][] matrixAddition(int[][] paraMatrix1, int[][] paraMatrix2) {int[][] resultMatrix = new int[paraMatrix1.length][paraMatrix1[0].length];for (int i = 0; i < paraMatrix1.length; i++) {for (int j = 0; j < paraMatrix1[0].length; j++) {resultMatrix[i][j] = paraMatrix1[i][j] + paraMatrix2[i][j];}}return resultMatrix;}/*** Unit test for respective method.*/public static void matrixAdditionTest() {int[][] tempMatrix = new int[3][4];for (int i = 0; i < tempMatrix.length; i++) {for (int j = 0; j < tempMatrix[0].length; j++) {tempMatrix[i][j] = i * 10 + j;}}System.out.println("The matrix is: \r\n" + Arrays.deepToString(tempMatrix));int[][] tempNewMatrix = matrixAddition(tempMatrix, tempMatrix);System.out.println("The new matrix is: \r\n" + Arrays.deepToString(tempNewMatrix));}
}

day8 矩阵相乘

8.1 题目解读

矩阵相乘(只有第一个矩阵的列和第二个矩阵的行相等): a矩阵(mn),b矩阵(np)则能相乘,且相乘后的矩阵为m*p。故在矩阵相乘是在一定条件下才能进行,需要用到if判断。
在这里插入图片描述

8.2代码

package basic;import java.util.Arrays;public class MatrixMultiplication {public static void main(String[] args) {matrixMultiplicationTest();}/*** Matrix multiplication. The columns of the first matrix should be equal to the rows of the second one.* @param paraFirstMatrix The first matrix.* @param paraSecondMatrix The second matrix* @return The result matrix.*/public static int[][] multiplication(int[][] paraFirstMatrix, int[][] paraSecondMatrix){//m*n n*p == m*pint m = paraFirstMatrix.length;int n = paraFirstMatrix[0].length;int p = paraSecondMatrix[0].length;// Step 1. Dimension check.if (paraSecondMatrix.length != n) {System.out.println("The two matrices cannot be multiplied.");return null;}// Step 2. The loop. m*n n*p == m*pint[][] resultMatrix = new int[m][p];for (int i = 0; i < m; i++) {for (int j = 0; j < p; j++) {for (int k = 0; k < n; k++) {resultMatrix[i][j] += paraFirstMatrix[i][k] * paraSecondMatrix[k][j];}}}return resultMatrix;}public static void  matrixMultiplicationTest(){int[][] tempFirstMatrix = new int[2][3];for (int i = 0; i < tempFirstMatrix.length; i++) {for (int j = 0; j < tempFirstMatrix[0].length; j++) {tempFirstMatrix[i][j] = i + j;}}System.out.println("The first matrix is: \r\n" + Arrays.deepToString(tempFirstMatrix));int[][] tempSecondMatrix = new int[3][2];for (int i = 0; i < tempSecondMatrix.length; i++) {for (int j = 0; j < tempSecondMatrix[0].length; j++) {tempSecondMatrix[i][j] = i * 10 + j;}}System.out.println("The second matrix is: \r\n" + Arrays.deepToString(tempSecondMatrix));int[][] tempThirdMatrix = multiplication(tempFirstMatrix, tempSecondMatrix);System.out.println("The third matrix is: \r\n" + Arrays.deepToString(tempThirdMatrix));System.out.println("Trying to multiply the first matrix with itself.\r\n");tempThirdMatrix = multiplication(tempFirstMatrix, tempFirstMatrix);System.out.println("The result matrix is: \r\n" + Arrays.deepToString(tempThirdMatrix));}
}

在这里插入图片描述

day9 while 语句

代码

还有一种循环是 do…while,其循环至少要执行一次循环体,而for和while循环需要先判断条件是否成立 在决定是否执行循环语句

package basic;public class WhileStatement {public static void main(String[] args) {whileStatementTest();}/*** The sum not exceeding a given value.*/public static void whileStatementTest() {int tempMax = 100;int tempValue = 0;int tempSum = 0;// Approach 1.while (tempSum <= tempMax) {tempValue++;tempSum += tempValue;System.out.println("tempValue = " + tempValue + ", tempSum = " + tempSum);}tempSum -= tempValue;System.out.println("The sum not exceeding " + tempMax + " is: " + tempSum);// Approach 2.System.out.println("\r\nAlternative approach.");tempValue = 0;tempSum = 0;while (true) {tempValue++;tempSum += tempValue;System.out.println("tempValue = " + tempValue + ", tempSum = " + tempSum);if (tempMax < tempSum) {break;}}tempSum -= tempValue;System.out.println("The sum not exceeding " + tempMax + " is: " + tempSum);}
}

在这里插入图片描述
在这里插入图片描述

day10 综合任务 1

10.1 题目解读

学生的成绩存放于一个矩阵,其中行表示学生,列表示科目。如:第 0 行表示第 0 个学生的数学、语文、英语成绩。要求:进行学生成绩的随机生成, 区间为 [50, 100];找出成绩最好、最差的同学。但有挂科的同学不参加评比.

  • 1.初始化学生成绩(会涉及到随机生成数据的区间范围:Random)
  • 2.通过for循环来计算学生总成绩并排除挂科同学(借助:break,continue关键字)
  • 3.for循环+if判断来找出成绩最好和最差的学生

10.2 代码

package basic;import java.util.Arrays;
import java.util.Random;
public class Task1 {public static void main(String[] args) {task1();}public static void task1(){//step1:Generate the data with n students and m courses.int n = 10;int m = 3;int lowerBound = 50;int upperBound = 100;int threshold = 60;// Here we have to use an object to generate random numbers.Random tempRandom = new Random();int[][] data = new int[n][m];for (int i = 0; i < n; i++) {for (int j = 0; j < m; j++) {data[i][j] = lowerBound + tempRandom.nextInt(upperBound - lowerBound);}}System.out.println("The data is:\r\n" + Arrays.deepToString(data));// Step 2. Compute the total score of each student.int[] totalScores = new int[n];for (int i = 0; i < n; i++) {for (int j = 0; j < m; j++) {if (data[i][j] < threshold) {totalScores[i] = 0;break;}totalScores[i] += data[i][j];}}System.out.println("The total scores are:\r\n" + Arrays.toString(totalScores));// Step 3. Find the best and worst student.// Typical initialization for index: invalid value.int tempBestIndex = -1;int tempWorstIndex = -1;// Typical initialization for best and worst values.// They must be replaced by valid values.int tempBestScore = 0;int tempWorstScore = m * upperBound + 1;for (int i = 0; i < n; i++) {// Do not consider failed students.if (totalScores[i] == 0) {continue;}if (tempBestScore < totalScores[i]) {tempBestScore = totalScores[i];tempBestIndex = i;}// Attention: This if statement cannot be combined with the last one using "else if", because a student can be both the best and the// worst. I found this bug while setting upperBound = 65.if (tempWorstScore > totalScores[i]) {tempWorstScore = totalScores[i];tempWorstIndex = i;}}// Step 4. Output the student number and score.if (tempBestIndex == -1) {System.out.println("Cannot find best student. All students have failed.");} else {System.out.println("The best student is No." + tempBestIndex + " with scores: "+ Arrays.toString(data[tempBestIndex]));}if (tempWorstIndex == -1) {System.out.println("Cannot find worst student. All students have failed.");} else {System.out.println("The worst student is No." + tempWorstIndex + " with scores: "+ Arrays.toString(data[tempWorstIndex]));}}
}

在这里插入图片描述

自我小结

三大结构

不管在c或者java,都会涉及到三大结构:顺序结构,选择结构,分支结构;通过对这三大结构的组合使用就可以解决一些很复杂的问题。
(1) 顺序结构:即按照代码的书写顺序依次执行,不存在跳转或者判断

  • 要避免代码冗余,可以通过封装相应的方法或类来避免;例如day4中我们可以专门封装一个方法来判断是否为闰年,而避免每次都去重复写来判断
  • 需要注意变量的使用范围等。例如day4中main方法中变量tempYear,正因为代码会顺序执行,所以可以对tempYear多次赋值从而覆盖前面的值。

(2)选择结构:会根据指定的判定条件去执行不同的代码块内容,如在day3,day4:if结构;if-else结构;if-else if结构;day5:switch结构

  • 在选择结构中,要保证我们的判定条件是正确的

(3)循环结构:会根据指定的条件重复执行一段代码块内容,直到条件不符合跳出循环,如在day6-9中 for循环,while循环,除此之外还有do…while循环

  • 循环条件要保证条件是能正确跳出循环条件的,否则会导致程序进入死循环

相关文章:

日撸 Java 三百行day1-10

文章目录说明day1 环境搭建1.1 开发环境1.2 package import 和 println1.3 编写HelloWorld.javaday2 基本算术操作2.1 加、减、乘、除、整除、取余.day3 基本if 语句3.1 if条件分支语句3.2 代码day4 闰年的计算4.1 思路整理&#xff1a;何为闰年&#xff1f;4.2 核心代码day5 基…...

Ubuntu Instant-ngp 训练自有数据集

1. 运行环境配置 conda create -n instant-ngp python3.10 conda activate instant-ngp pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple2. COLMAP稀疏重建生成transform.json colmap 环境配置参考文档&#xff1b; 终端定位在instant-ngp/da…...

k8s集群只一台节点,重启节点后命名空间找不到了

定位 如果您的Kubernetes集群只有一台节点&#xff0c;并且在重启节点之前您创建了一些命名空间和资源&#xff0c;那么在节点重启后&#xff0c;这些命名空间和资源可能会丢失。这是因为在Kubernetes中&#xff0c;资源和命名空间通常是存储在etcd中的。当节点重启时&#xf…...

MarkDown示例

这里写自定义目录标题欢迎使用Markdown编辑器新的改变功能快捷键合理的创建标题&#xff0c;有助于目录的生成如何改变文本的样式插入链接与图片如何插入一段漂亮的代码片生成一个适合你的列表创建一个表格设定内容居中、居左、居右SmartyPants创建一个自定义列表如何创建一个注…...

spring cloud 雪崩效应

什么是雪崩效应 雪崩就是塌方。在山坡上的积雪&#xff0c;如果积雪的内聚力小于重力或其他力量&#xff0c;则积雪便向下滑动&#xff0c;从而逐渐引起积雪的崩塌。 在微服务架构中&#xff0c;服务之间通常存在级联调用。比如&#xff0c;服务A调用服务B&#xff0c;而服…...

Python 自动化指南(繁琐工作自动化)第二版:三、函数

原文&#xff1a;https://automatetheboringstuff.com/2e/chapter3/ 您已经熟悉了前几章中的print()、input()和len()函数。Python 提供了几个这样的内置函数&#xff0c;但是您也可以编写自己的函数。函数就像一个程序中的一个小程序。 为了更好地理解函数是如何工作的&#…...

c++多线程 1

https://www.runoob.com/cplusplus/cpp-multithreading.html 两种类型的多任务处理&#xff1a;基于进程和基于线程。 基于进程的多任务处理是程序的并发执行。 基于线程的多任务处理是同一程序的片段的并发执行。 线程 c11以后有了 标准库 1 函数 2 类成员函数 3 lambda函…...

STM32F103制作FlashDriver

文章目录前言芯片内存定义实现过程FlashDriver生成段定义擦除函数写入函数编译后的map手动测试HexView提取指定地址内容并重映射总结前言 在汽车行业控制器软件刷新流程中&#xff0c;一般会将Flash驱动单独进行刷写&#xff0c;目的是防止程序中一直存在Flash驱动的话&#x…...

springboot树形结构接口, 懒加载实现

数据库关系有父子id的, 作为菜单栏展示时需要用前端需要用到懒加载, 所谓懒加载就是接口有一个标志位isLeaf, 前端请求后通过该字段判断该节点是否还有子节点数据 创建数据库表 t_company_info结构有id和parentId标识, 用来表示父子关系 /*Navicat Premium Data TransferSourc…...

java企业级信息系统开发学习笔记02初探spring——利用组件注解符精简spring配置文件

文章目录一、学习目标二、打开01的项目三、利用组件注解符精简spring配置文件&#xff08;一&#xff09;创建新包&#xff0c;复制四个类&#xff08;二&#xff09;修改杀龙任务类&#xff08;三&#xff09;修改救美任务类&#xff08;四&#xff09;修改勇敢骑士类&#xf…...

用Python发送电子邮件?这也太丝滑了吧(21)

小朋友们好&#xff0c;大朋友们好&#xff01; 我是猫妹&#xff0c;一名爱上Python编程的小学生。 欢迎和猫妹一起&#xff0c;趣味学Python。 今日主题 猫爸赚钱养家&#xff0c;细想起来真的不容易啊&#xff01; 起早贪黑&#xff0c;都是6点早起做早饭&#xff0c;送…...

分类预测 | MATLAB实现CNN-GRU-Attention多输入分类预测

分类预测 | MATLAB实现CNN-GRU-Attention多输入分类预测 目录分类预测 | MATLAB实现CNN-GRU-Attention多输入分类预测分类效果模型描述程序设计参考资料分类效果 模型描述 Matlab实现CNN-GRU-Attention多变量分类预测 1.data为数据集&#xff0c;格式为excel&#xff0c;12个输…...

C++提高编程(1)

C提高编程1.模板1.1模板的概念1.2函数模板1.2.1函数模板语法1.2.2函数模板注意事项1.2.3函数模板案例1.2.4普通函数与函数模板的区别1.2.5普通函数与函数模板的调用规则1.2.6模板的局限性1.3类模板1.3.1类模板语法1.3.2类模板和函数模板区别1.3.3类模板中成员函数创建时机1.3.4…...

day26 回溯算法的部分总结

回溯算法的部分总结 回溯算法是一种常用于解决排列组合问题、搜索问题的算法&#xff0c;它的基本思想是将问题的解空间转化为一棵树&#xff0c;通过深度优先搜索的方式遍历树上的所有节点&#xff0c;找到符合条件的解。回溯算法通常使用递归实现&#xff0c;每次递归时传入…...

带你玩转Python爬虫(胆小者勿进)千万别做坏事·······

这节课很危险&#xff0c;哈哈哈哈&#xff0c;逗你们玩的 目录 写在前面 1 了解robots.txt 1.1 基础理解 1.2 使用robots.txt 2 Cookie 2.1 两种cookie处理方式 3 常用爬虫方法 3.1 bs4 3.1.1 基础介绍 3.1.2 bs4使用 3.1.2 使用例子 3.2 xpath 3.2.1 xpath基础介…...

【JavaScript 】严格模式,With关键字,测试框架介绍,assert

❤️ Author&#xff1a; 老九 ☕️ 个人博客&#xff1a;老九的CSDN博客 &#x1f64f; 个人名言&#xff1a;不可控之事 乐观面对 &#x1f60d; 系列专栏&#xff1a; 文章目录静态类型语言弱类型严格模式将过失错误转化为异常简化变量的使用With测试框架try-catch选择性捕获…...

mybatis实现一个简单的CRUD功能的小案例(后端)编写流程

下面是一个使用mybatis实现增删改查功能的示例程序&#xff1a; 1.创建一个数据库 首先需要创建一个名为test_db的数据库&#xff0c;里面包含一个名为user_info的表&#xff0c;其中包含id、name、age三个字段。 2.配置mybatis 在项目的pom.xml文件中添加mybatis和mysql依…...

腾讯云轻量应用服务器价格表(2023版)

2023腾讯云轻量应用服务器2核2G4M带宽88元一年、2核4G6M带宽159元/年、4核8G10M优惠价425元、8核16G14M价格1249、16核32G20M服务器2499元一年&#xff0c;今天分享2023腾讯云服务器配置及精准报价。 腾讯云轻量应用服务器优惠价格表 腾讯云服务器分为轻量应用服务器和云服务器…...

网络层IP协议和数据链路层

目录IP协议协议头格式分片网段划分特殊的IP地址IP地址的数量限制NAT技术NAT技术背景NAT IP转换过程NAPTNAT技术的缺陷NAT和代理服务器私有IP地址和公网IP地址路由路由表生成算法数据链路层认识以太网以太网帧格式认识MAC地址对比理解MAC地址和IP地址认识MTUMTU对IP协议的影响MT…...

零基础学习Java 03

目录 数组 动态初始化数组 静态初始化 数组的应用 数组两种典型的异常 length关键字求出数组的长度 数组遍历在IDEA中输出快捷语句 对象数组 数组的遍历&#xff1a;foreach方法 二维数组 枚举(enum) 数组 1在方法中可以返回一个数组&#xff0c;但是在定义方法时类型要…...

可靠性+灵活性:电力载波技术在楼宇自控中的核心价值

可靠性灵活性&#xff1a;电力载波技术在楼宇自控中的核心价值 在智能楼宇的自动化控制中&#xff0c;电力载波技术&#xff08;PLC&#xff09;凭借其独特的优势&#xff0c;正成为构建高效、稳定、灵活系统的核心解决方案。它利用现有电力线路传输数据&#xff0c;无需额外布…...

django filter 统计数量 按属性去重

在Django中&#xff0c;如果你想要根据某个属性对查询集进行去重并统计数量&#xff0c;你可以使用values()方法配合annotate()方法来实现。这里有两种常见的方法来完成这个需求&#xff1a; 方法1&#xff1a;使用annotate()和Count 假设你有一个模型Item&#xff0c;并且你想…...

C++八股 —— 单例模式

文章目录 1. 基本概念2. 设计要点3. 实现方式4. 详解懒汉模式 1. 基本概念 线程安全&#xff08;Thread Safety&#xff09; 线程安全是指在多线程环境下&#xff0c;某个函数、类或代码片段能够被多个线程同时调用时&#xff0c;仍能保证数据的一致性和逻辑的正确性&#xf…...

并发编程 - go版

1.并发编程基础概念 进程和线程 A. 进程是程序在操作系统中的一次执行过程&#xff0c;系统进行资源分配和调度的一个独立单位。B. 线程是进程的一个执行实体,是CPU调度和分派的基本单位,它是比进程更小的能独立运行的基本单位。C.一个进程可以创建和撤销多个线程;同一个进程中…...

python爬虫——气象数据爬取

一、导入库与全局配置 python 运行 import json import datetime import time import requests from sqlalchemy import create_engine import csv import pandas as pd作用&#xff1a; 引入数据解析、网络请求、时间处理、数据库操作等所需库。requests&#xff1a;发送 …...

【FTP】ftp文件传输会丢包吗?批量几百个文件传输,有一些文件没有传输完整,如何解决?

FTP&#xff08;File Transfer Protocol&#xff09;本身是一个基于 TCP 的协议&#xff0c;理论上不会丢包。但 FTP 文件传输过程中仍可能出现文件不完整、丢失或损坏的情况&#xff0c;主要原因包括&#xff1a; ✅ 一、FTP传输可能“丢包”或文件不完整的原因 原因描述网络…...

Vue 3 + WebSocket 实战:公司通知实时推送功能详解

&#x1f4e2; Vue 3 WebSocket 实战&#xff1a;公司通知实时推送功能详解 &#x1f4cc; 收藏 点赞 关注&#xff0c;项目中要用到推送功能时就不怕找不到了&#xff01; 实时通知是企业系统中常见的功能&#xff0c;比如&#xff1a;管理员发布通知后&#xff0c;所有用户…...

window 显示驱动开发-如何查询视频处理功能(三)

​D3DDDICAPS_GETPROCAMPRANGE请求类型 UMD 返回指向 DXVADDI_VALUERANGE 结构的指针&#xff0c;该结构包含特定视频流上特定 ProcAmp 控件属性允许的值范围。 Direct3D 运行时在D3DDDIARG_GETCAPS的 pInfo 成员指向的变量中为特定视频流的 ProcAmp 控件属性指定DXVADDI_QUER…...

以太网PHY布局布线指南

1. 简介 对于以太网布局布线遵循以下准则很重要&#xff0c;因为这将有助于减少信号发射&#xff0c;最大程度地减少噪声&#xff0c;确保器件作用&#xff0c;最大程度地减少泄漏并提高信号质量。 2. PHY设计准则 2.1 DRC错误检查 首先检查DRC规则是否设置正确&#xff0c;然…...

Modbus转Ethernet IP深度解析:磨粉设备效率跃升的底层技术密码

在建材矿粉磨系统中&#xff0c;开疆智能Modbus转Ethernet IP网关KJ-EIP-101的应用案例是一个重要的技术革新。这个转换过程涉及到两种主要的通信协议&#xff1a;Modbus和Ethernet IP。Modbus是一种串行通信协议&#xff0c;广泛应用于工业控制系统中。它简单、易于部署和维护…...