当前位置:网站首页>2022-07-14 第五小组 修身课 学习笔记(every day)
2022-07-14 第五小组 修身课 学习笔记(every day)
2022-07-15 10:37:00 【修身课】
学习心情:认真学习
目录
导图

Scanner
Scanner 类
一个可以解析基本类型和字符串的文本扫描器,例如以下代码能使用户能够从System.in 中读取一个数
java中规定,双引号括起来的字符串是不可变的
Scanner sc = new Scanner(System.in);
int i = sc.nextInt();创建对象
数据类型 变量名 = new 数据类型(System.in);String
String表示字符串类型,属于 引用数据类型,不属于基本数据类型。
在java中随便使用 双引号括起来 的都是String对象。
java中规定,双引号括起来的字符串,是不可变的的,
字符串对象之间的比较不能使用“== ”,"=="不保险。应该调用String类的equals方法。
leaght():获取字符串长度
concat():拼接字符串
equals():字符串比较
循环
while循环
语法:
while(循环条件){
循环体;
}
do...while循环
语法:
do{
循环体;
}while(循环条件);
for循环
语法:
for(循环变量;循环条件;改变循环变量){
循环体
}
foreach() (增强for循环)
int[][] sparsArray1= new int[11][11];
sparsArray1[2][1]=3;
sparsArray1[3][5]=4;
for (int[] row:sparsArray1) {
for (int item:
row) {
System.out.print("\t"+item);
}
System.out.println();
}死循环
for(;;){}
while(true){}
数组
容器:是将多个数据存储到一起,每个数据称为该容器的元素。
数组概念:数组就是存储数据长度固定的容器,保证多个数据的数据类型要一致。
定义
方式1:数组存储的数据类型[] 数组名字 = new 数组存储的数据类型[长度];
方式2:数据类型[] 数组名 = new 数据类型[]{元素1,元素2,元素3…};
方式3:数据类型[] 数组名 = {元素1,元素2,元素3…};
数组的访问
索引: 每一个存储到数组的元素,都会自动的拥有一个编号,从0开始,这个自动编号称为数组索引 (index),可以通过数组的索引访问到数组中的元素。
格式:
数组名[索引]
数组的长度属性: 每个数组都具有长度,而且是固定的,Java中赋予了数组的一个属性,可以获取到数组的 长度,语句为: 数组名.length ,属性length的执行结果是数组的长度,int类型结果。由次可以推断出,数 组的最大索引值为 数组名.length-1
索引访问数组中的元素:
数组名[索引]=数值,为数组中的元素赋值
变量=数组名[索引],获取出数组中的元素
数组空指针异常
public static void main(String[] args) {
int[] arr = {1,2,3,4,5};
arr = null;
System.out.println(arr[0]);
}arr = null 这行代码,意味着变量arr将不会在保存数组的内存地址,也就不允许再操作数组了,因此运行的时候 会抛出 NullPointerException 空指针异常。在开发中,数组的越界异常是不能出现的,一旦出现了,就必须要修 改我们编写的代码。
数组遍历
就是将数组中的每个元素分别获取出来,就是遍历。遍历也是数组操作中的基石。
for (int[] row:sparsArray1) {
for (int item:
row) {
System.out.print("\t"+item);
}
System.out.println();
}for (int i = 0; i < sparsArray2.length; i++) {
System.out.printf("%d\t%d\t%d\t",sparsArray2[i][0],sparsArray2[i][1],sparsArray2[i][2]);
System.out.println();
}for (int i = 0; i <sparsArray1.length ; i++) {
for (int j = 0; j < sparsArray1.length; j++) {
System.out.println(sparsArray1[i][j])
}
System.out.println();
}流程控制
顺序结构
指程序从上向下依次执行每条语句的结构.
选择结构
是根据条件判断的结果来选择执行不同的代码.通常通过if语句、switch语句来实现选择结构.
简单的选择结构
if语句的格式如下:
if(表达式){
//代码块
}循环结构
是根据判断条件来重复性地执行某段代码.通常通过while语句、do-while语句和for语句来实现循环结构.
总结
充实学好每一天,变得越来越好
边栏推荐
- How Axure achieves screen adaptation
- matlab 疑问
- Summary of Halcon common image preprocessing operators
- 百度搜索基础信息设置规范,有哪些我们需要注意的问题呢?
- [practice C] xiaolele walks up the steps
- Introduction to redis
- 善良的人都晚熟
- Common SQL statements, stored procedures and functions
- How can Volvo be confident to maintain "zero casualties" in traffic safety in the era of electrification?
- 【HCIA】数通网络基础
猜你喜欢

手机浏览器产品分析

【C】数组的地址

在线综艺冷场:“爱优腾芒”放不开,“抖快B”拿不下

Cloud mall source code repair 30 sets of templates to support one click docking of major systems
![[latex Chinese and English style & Bold] freely choose Chinese and English font styles, and set the bold and black degree of Chinese and English fonts](/img/36/db868e14b32b9f42c7c0dd9187d6a8.png)
[latex Chinese and English style & Bold] freely choose Chinese and English font styles, and set the bold and black degree of Chinese and English fonts

Today's sleep quality record is 80 points

【C 练习】输入年月,求出月份天数

百家号排名会丢吗,不稳定怎么办?

STM32 application development practice tutorial: application development of environmental light intensity monitoring

STM32 application development practice tutorial: application development of persistent storage of environmental parameters
随机推荐
【Verilog】32位单精度浮点数比较大小
Data Lake (XVII): Flink and iceberg integrate datastream API operations
反射面试
VDD,VCC,VSS,GND,地之间有何区别?
百家号排名不错,转化率怎么提升呢?
cdn加速是什么
[C exercise] delete the specified number in the sequence
机器学习预备知识:分类与回归
C语言实现手机通讯录
After the WebView page of the applet is forwarded, open the page blank
网络安全(2)
Typescript 14 starting from 0: built in tool type
Matlab中响应鼠标的事件
高权重没备案网站,批量降权,正常吗?
2020ccpc Qinhuangdao exam results (ruler)
Calculation method engineering mathematics first lesson Doolittle
百度搜索基础信息设置规范,有哪些我们需要注意的问题呢?
Redis入门介绍
.net core 配置跨域
网络安全(1)