提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档
文章目录
- 1-7天
- 前言
- 一.配置环境
- 二.基本语法
- 三.作业
- 小结
1-7天
前言
为了复习java基础知识
一.配置环境
一般用java8
二.基本语法
.2.1 加、减、乘、除、整除、取余.2.2 熟悉 println 的中阶用法2.3if else以及if else的嵌套2.4switch case2.5fro循环和增强for循环以及while循环
三.作业
import java.util.Random;
import java.util.Scanner;/*** @Auther: pql* @Date: 2022/4/3 - 04- 03- 15:51* @Description: PACKAGE_NAME* @version: 1.0*/
public class Tset {public static void fu_zhi(int a[][]){for (int i = 0; i <a.length ; i++) {for (int j = 0; j <a[i].length ; j++) {int score = (int)(50+Math.random()*51);//Math.random()是令系统随机选取大于等于 0.0 且小于 1.0 的伪随机 double 值//获取指定范围的随机数:(数据类型)(最小值+Math.random()*(最大值-最小值+1))a[i][j] = score;}}int k=0; //换行标记for (int i = 0; i <a.length ; i++) {for (int j = 0; j <a[i].length ; j++) {k++;System.out.print(a[i][j]+" ");if (k==a[j].length){System.out.println();k=0; //换了一行之后让k回到初始状态}}}}public static void max_min(int a[][]){int max=-999;int min=9999;/*获取二维数组的行数:数组名.length获取二维数组第i的的列数:a[i].length*/for (int i = 0; i <a.length ; i++) {for (int j = 0; j <a[i].length; j++) {if(a[i][j]<60) continue;else if(a[i][j]>=60&&a[i][j]>max)max = a[i][j];else if(a[i][j]>=60&&a[i][j]<min)min = a[i][j];}}System.out.println("max is "+ max +" min is "+min);}public static void main(String[] args) {Scanner scanner = new Scanner(System.in);int studentCount = scanner.nextInt();//学生人数int subjectCount = scanner.nextInt();//科目数int [][]sc = new int[studentCount][subjectCount];fu_zhi(sc);max_min(sc);}
}
结果
eg1
eg2
注:求随机数的方法
.通过java.Math包的random方法得到0-1的随机数(不包括1包括0)(数据类型)(最小值+Math.random()*(最大值-最小值+1)
小结
复习了分支语句 (if, switch case), 循环语句 (for, while), 流程控制语句 (continue, break), 函数的使用