当前位置:网站首页>2022-07-14 study notes of group 5 self-cultivation class (every day)
2022-07-14 study notes of group 5 self-cultivation class (every day)
2022-07-18 01:50:00 【Self cultivation class】
Learning mood : Study carefully
Catalog
Guide map

Scanner
Scanner class
One can resolve basic types and character string Text scanner for , For example, the following code enables the user to from System.in Read a number from
java Specified in the , Strings enclosed in double quotes are immutable
Scanner sc = new Scanner(System.in);
int i = sc.nextInt();Create objects
data type Variable name = new data type (System.in);String
String Represents string type , Belong to Reference data type , Not a basic data type .
stay java Use casually in In double quotation marks The are String object .
java Specified in the , A string in double quotation marks , Is immutable ,
Comparisons between string objects cannot use “== ”,"==" No insurance . Should be called String class Of equals Method .
leaght(): Get string length
concat(): String concatenation
equals(): String comparison
loop
while loop
grammar :
while( The loop condition ){
The loop body ;
}
do...while loop
grammar :
do{
The loop body ;
}while( The loop condition );
for loop
grammar :
for( Loop variable ; The loop condition ; Change the loop variables ){
The loop body
}
foreach() ( enhance for loop )
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();
}Dead cycle
for(;;){}
while(true){}
Array
Containers : It's storing multiple data together , Each data is called the element of the container .
Array concept : An array is a container that stores data of fixed length , Ensure that the data types of multiple data are consistent .
Definition
The way 1: The data type stored in the array [] Array name = new The data type stored in the array [ length ];
The way 2: data type [] Array name = new data type []{ Elements 1, Elements 2, Elements 3…};
The way 3: data type [] Array name = { Elements 1, Elements 2, Elements 3…};
Array access
Indexes : Every element stored in an array , Will automatically have a number , from 0 Start , This automatic number is called an array index (index), You can access the elements of the array through the index of the array .
Format :
Array name [ Indexes ]
The length property of an array : Each array has length , And it's fixed ,Java An attribute of the array is given in , You can get the of the array length , Statement for : Array name .length , attribute length The result is the length of the array ,int Type the results . It can be inferred from this that , Count The maximum index value for a group is Array name .length-1
Index access to elements in an array :
Array name [ Indexes ]= The number , Assign values to elements in an array
Variable = Array name [ Indexes ], Get the elements in the array
Array null pointer exception
public static void main(String[] args) {
int[] arr = {1,2,3,4,5};
arr = null;
System.out.println(arr[0]);
}arr = null This line of code , It means variable arr The memory address of the array will not be saved , You are not allowed to manipulate arrays anymore , So when running Will throw out NullPointerException Null pointer exception . In development , Array out of bounds exception is not allowed , Once it appears , It must be repaired Change the code we write .
Array traversal
Is to get each element of the array separately , It's traversal . Traversal is also the cornerstone of array operations .
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();
}Process control
Sequential structure
Refers to the structure of each statement executed by the program from top to bottom .
Selection structure
It is to choose and execute different codes according to the result of condition judgment . Usually by if sentence 、switch Statement to implement the selection structure .
Simple choice structure
if The format of the statement is as follows :
if( expression ){
// Code block
}Loop structure
It is to execute a piece of code repeatedly according to the judgment conditions . Usually by while sentence 、do-while Statement and for Statement to realize the loop structure .
summary
Enrich and learn every day , Get better and better
边栏推荐
- 第五十三期:彻底理解MVC,MVP和MVVM
- Analysis of problems related to C language pointer
- LeetCode 剑指 Offer 53 - I. 在排序数组中查找数字 I 03
- Mysql事务
- After writing a paper in 2 hours, why gpt-3 doesn't deserve a name?
- [C exercise] inverted string
- 【C】 Creation and destruction of function stack frames
- 【C】 Const decorated pointer
- Description and simple implementation of intelligent pointer
- C# Winform窗体基础属性
猜你喜欢

【C 练习】变种水仙花数

【HCIA】数通网络基础

STM32 application development practice tutorial: application development of persistent storage of environmental parameters

“OpenCvSharp.Mat“的类型初始值设定项引发异常

STM32应用开发实践教程:环境温湿度监测的应用开发

Structure related type resolution

nosql概述

送你的代碼上太空,與華為雲一起開發“最偉大的作品”

Servlet API 代码示例:服务器版表白墙

Redis persistence - RDB
随机推荐
Which is more suitable to be an advanced anti DDoS server, cloud server or physical machine
AI应用启示录:安防市场的蜜糖和砒霜
【C 练习】求n的k次方(递归实现)
.net core 配置跨域
redis事务和消息订阅发布
[C exercise] input the month and year, and calculate the number of days in the month
System. Use of arraycopy and detailed explanation of parameter meaning
[practice C] xiaolele walks up the steps
After the WebView page of the applet is forwarded, open the page blank
[C exercise] inverted string
STM32 application development practice tutorial: application development of persistent storage of environmental parameters
C语言实现简单扫雷游戏(二维数组)
百度搜索基础信息设置规范,有哪些我们需要注意的问题呢?
[HCIA] OSI model
STM32应用开发实践教程:环境光照强度监测的应用开发
VDD,VCC,VSS,GND,地之间有何区别?
知乎SEO怎么做,如何提高知乎SEO排名?
持久化分析
【C】 Practical debugging skills
Implementation of mobile phone address book in C language