总体要求:
1.1 程序设计
原文链接:https://blog.csdn.net/minfanphd/category_11067052.html
1.2 英语
每天背 50 个单词,循环记忆。
2021.12.15——2021.12.21
2021.12.15
(一)while 语句
9.1 while 语句本质上比 for 更基础, 因此可以替代后者. 但 for 在很多时候更方便.
9.2 break 语句又出现了, 上次是在 switch 语句里. 都是表示跳出当前代码块.
学习情况:
因为要保证累加得到的数不超过给定的最大值,则需要减去最后加上的值。
package week2;
public class Test1 {
public static void main(String[] args) {
whileStatementTest();
}
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(tempSum > tempMax){
break;
}
}
tempSum -= tempValue;
System.out.println("The sum not exceeding " + tempMax + " is: " + tempSum);
}
}
(二)英语单词(64个)
2021.12.16
(一)综合任务 1
学生的成绩存放于一个矩阵,其中行表示学生,列表示科目。如:第 0 行表示第 0 个学生的数学、语文、英语成绩。要求:
进行学生成绩的随机生成, 区间为 [50, 100].
找出成绩最好、最差的同学。但有挂科的同学不参加评比.
10.1 实际代码中,for 和 if 是最常见的, switch 和 while 使用少得多.
10.2 使用了 continue, 它是指继续跳过本次循环后面的代码,直接进入下一次循环. 而 break 是跳出整个循环体.
10.3 为了随机数,迫不得已提前使用了 new 语句生成对象.
10.4 通过数据测试找出程序中的 bug.
1)随机数生成:
Random random = new Random();
int a = random.nextInt(51) + 50; //random.nextInt(51) means [0,51)
package week2;
import java.util.Arrays;
import java.util.Random;
public class Test2 {
public static void main(String[] args) {
getScore();
}
public static int[][] getScoreMatrix(){
int m = 10;
int n = 3;
Random random = new Random();
int[][] score = new int[m][n];
for(int i = 0; i < m; i++){
for(int j = 0; j < n; j++){
score[i][j] = random.nextInt(51) + 50;
}
}
System.out.println(Arrays.deepToString(score));
return score;
}
public static void getScore(){
int[][] score = getScoreMatrix();
int[] scoreSum = new int[score.length];
for(int i = 0; i < score.length; i++){
for(int j = 0; j < score[0].length; j++){
if(score[i][j] < 60){
scoreSum[i] = 0;
break;
}
scoreSum[i] += score[i][j];
}
}
System.out.println(Arrays.toString(scoreSum));
int max = scoreSum[0];
int min = scoreSum[0];
int maxIndex = 0;
int minIndex = 0;
for(int i = 0; i < scoreSum.length; i++){
if(scoreSum[i] == 0){
continue;
}
if(max < scoreSum[i]){
max = scoreSum[i];
maxIndex = i;
}
if(min > scoreSum[i]){
min = scoreSum[i];
minIndex = i;
}
}
System.out.println("The best score is : " + Arrays.toString(score[maxIndex]));
System.out.println("The worst score is : " + Arrays.toString(score[minIndex]));
}
}
(二)英语单词(39个)
2021.12.17
(一)顺序表 一
11.1 对象: 数据及其上操作的总和. 例如, 我是一个对象, 具有身高、体重、年龄、跑步速度等数据; 同时,我具有吃饭、睡觉、送快递等功能. 从计算机的发展来看, 第一阶段以操作 (函数) 为中心, 一个计算导弹轨迹的函数, 根据不同输入获得不同输出. 第二阶段以数据为中心, 即数据存放于数据库, 使用不同的算法来处理它. 第三阶段认为数据及其上的操作是统一不可分的, 这就到了面向对象