

AP期末2
Presentation
•
Computers
•
10th Grade
•
Practice Problem
•
Hard
Arasaka Teacher
Used 1+ times
FREE Resource
41 Slides • 5 Questions
1
Multiple Choice
Which of the following logical statements is equivalent to
!(A && B)
Where A and B are boolean values
2
Multiple Choice
Which expression is true?
true && !true
!false || !true
true && false
false || false || !true
3
Fill in the Blanks
4
Fill in the Blanks
5
Fill in the Blanks
6
String类
7
获取字符串长度
8
我们注册qq账户的时候,可以看见有这样一条提示:
注册账号时碰到的问题
9
“12345678”
掌握
什么是字符串的长度
长度为8
10
如何获取字符串长度
public int length()
语法
String password="1234567890";
int size = password.length();
示例
字符串用length()
数组用length
11
length()方法返回的字符串长度包括字符串中的空格。
获取字符串长度的注意事项
String str = “123 45”;
int size = str.length();
123和45之间有一个空格
这时的size是6,而不是5
12
获取字符串长度的注意事项
String str = null;
str.length();
String str = "ABCDE";
str.length();
null字符串不能使用length()
13
获取子字符串的位置
14
子字符串
新来的你
叫什么?
王大锤
15
Java中获取子字符串位置有4种方法:
获取子字符串索引位置
1. public int indexOf(String str)
2. public int indexOf(String str, int fromIndex)
3. public int lastIndexOf(String str)
4. public int lastIndexOf(String str, int fromIndex)
掌握
了解
掌握
了解
获取第一次出现的索引
从指定位置往后查
从指定位置往前查
获取最后一次出现的索引
16
获取第一次出现的索引
返回e第一次出现的位置
public int indexOf(String str )
语法
要获取的子字
符串
String str = "We are the world";
int index = str.indexOf(“e”);
示例
17
获取第一次出现的索引
返回e在索引3之后出现的位置
public int indexOf(String str , int fromIndex )
语法
String str = "We are the world";
int index = str.indexOf(“e”, 3);
示例
要获取的子字
符串
起始位置
18
获取倒数第一次出现的索引
返回t最后第一次出现的位置
public int lastIndexOf(String str )
语法
要获取的子字
符串
String str = “Let it go!Let it go!”;
int lastIndex = str.lastIndexOf(“t”);
示例
19
获取倒数第一次出现的索引
返回的位置
public int lastIndexOf(String str, int fromIndex)
语法
String str = “Let it go!Let it go!”;
int lastIndex2 = str.lastIndexOf(“t”,14);
示例
要获取的子字
符串
起始位置
20
判断字符串首尾内容
21
上传的文件只能是“.rar”“.jpg”“.gif”“.bmp”“.png”,如何判断文件的后缀呢?
文件的后缀名
22
判断字符串结尾内容
String fileName = “HelloWorld.java”;
public boolean endsWith(String suffix )
语法
String fileName = “HelloWorld.java”;
Boolean bool1 = fileName. endsWith(“.java”);
Boolean bool2 = fileName. endsWith(“.jpg”);
示例
要对比的字符
串
23
判断字符串句首内容
public boolean startsWith(String prefix )
语法
String str = “新华社记者从前往发来报道……”;
Boolean bool1 = str. startsWith(“新华社”);
Boolean bool2 = str. startsWith(“新华书店”);
示例
要对比的字符
串
24
判断子字符串是否存在
25
加班的故事
26
判断子字符串是否存在
public boolean contains (String string )
语法
要查找的子字符
串
String str= “8888B888”;
Boolean bool1 = str. endsWith(“B”);
Boolean bool2 = str. endsWith(“H”);
示例
27
使用indexOf()方法判断
str.indexOf(“B”);
判断字符串中
是否有”B”这个
子字符串
返回”B”的索引
位置
true
返回 -1
false
这个值肯定是
大于等于0的
这个值就是
-1
28
截取字符串
29
从身份证号中获取出生日期
截取字符串,将出生日期
截取出来。
30
两种用法:
截取字符串
1. public String substring(int beginIndex)
2. public String substring(int beginIndex, int endIndex)
指定开始的位置
指定开始的位置
和结束的位置
31
从指定位置开始截取
public String substring(int beginIndex )
语法
String id = “123456196108047890”;
String birthdate = id.substring(6);
示例
开始截取的位
置
32
截取指定的范围
public String substring(int beginIndex , int endIndex )
语法
String id = “123456196108047890”;
String birthdate = id.substring(6,14);
示例
开始截取的位
置
截取结束的位
置
33
Using the substring method with one parameter, what will be the output
of the following Java code?
String str = "Programming";
String result = str.substring(3);
System.out.println(result);
(A)Program
(B)ming
(C)gramming
(D)Pro
34
Ø 简单问题:求4个整数的最大值?
Ø 如何表示4个整数?
Ø 如何求出最大值?
int a = 40, b = 60, c = 30, d = 65;
int max = a;
if (b > max) max = b;
if (c > max) max = c;
if (d > max) max = d;
System.out.println(max);
用4个整数变量
逐一比较这4个变量
想一想?
35
Ø 引申问题:求n个整数的最大值?
Ø n的值很大时,仍然采用前面的方法可不可行?
int a1 = 2, a2 = 3, ..., an = 100;
int max = a1;
if (a2 > max) max = a2;
if (a3 > max) max = a3;
......
if (an > max) max = an;
System.out.println(max);
定义繁琐
代码冗长
想一想?
36
Ø 如何解决前面遇到的问题呢?
Ø 将n个同类型的变量以整体的形式表示
Ø 能够以简单的方式访问整体中的每个元素
数组
37
一维数组
38
什么是数组?
第
1
格
第
2
格
第
3
格
第
4
格
第
5
格
0
1
2
3
4
下标
39
1、2、3、4、5
整型数组
1.1、2.1、3.1、4.1、5.1
浮点型数组
A、B、C、D、E、F
字符数组
“张三”、”李四”、”王五”
字符串数组
常见的一维数组
40
创建一维数组
两种语法效果完全一样
数组元素类型数组名字[] ;
数组元素类型[] 数组名字;
语法
41
一维数组初始化
int c[] = { 8, 4, 9 };
int b[] = newint[] { 5, 1, 3 };
int a[] = newint[3];
a[0] = 7;
a[1] = 2;
a[2] = 6;
三种初始化方法
第一个元素
从0开始
42
13
27
45
new int[3];
arr[0] = 13;
arr[1] = 27;
arr[2] = 45;
内存中的数组
int arr[] = newint[3];
arr[0] = 13;
arr[1] = 27;
arr[2] = 45;
第一个元素
从0开始
第三个元素的索引
是2,不是3
43
int arr[] = newint[] { 13, 27, 45 };
int arr[] = { 13, 27, 45 };
13
27
45
new int[3];
arr[0] = 13;
arr[1] = 27;
arr[2] = 45;
内存中的数组
44
int arr[] = newint[3] { 5, 1, 7 };
int arr[] = newint[] { 5, 1, 7 };
int arr[] = newint[3];
char ch[] = { ‘a’,’b’,’c’};
ch[3] = ‘d’;
a
b
c
0 1 2
3
?
语法错误
下标越界
下标从0开始
45
数组的length属性
int a[] =new int[15];
a.length
15
返回数组长度
1.length返回的是int型。
2.数组长度不可以定义成负数。
3.length的值是常量。
46
求n个整数的最大值
int a1 = 2, a2 = 3, ..., an = 100
a
if (a2 > max) max = a2;
if (a3 > max) max = a3;
......
if (an > max) max = an;
for (int i = 0; i < a.length; i++) {
if (a[i] > max) {
max = a[i];
}
}
Which of the following logical statements is equivalent to
!(A && B)
Where A and B are boolean values
Show answer
Auto Play
Slide 1 / 46
MULTIPLE CHOICE
Similar Resources on Wayground
39 questions
9th 买衣服
Presentation
•
9th Grade
36 questions
python_datetype_methods(list)
Presentation
•
10th Grade
46 questions
Technology - Part 1 [ESL]
Presentation
•
10th - 11th Grade
42 questions
第二课 鱼我所欲也
Presentation
•
10th - 12th Grade
40 questions
AQA String Manipulation
Presentation
•
10th Grade
43 questions
DATOS METODOLOGÍA DE LA PROGRAMACIÓN
Presentation
•
10th Grade
42 questions
Taller recuperación 10
Presentation
•
10th Grade
40 questions
Unit 4 Test Review: Properties of matter, density, IMF
Presentation
•
11th Grade
Popular Resources on Wayground
20 questions
Math Review
Quiz
•
3rd Grade
15 questions
Fast food
Quiz
•
7th Grade
20 questions
Context Clues
Quiz
•
6th Grade
20 questions
Inferences
Quiz
•
4th Grade
19 questions
Classifying Quadrilaterals
Quiz
•
3rd Grade
20 questions
Figurative Language Review
Quiz
•
6th Grade
20 questions
Equivalent Fractions
Quiz
•
3rd Grade
10 questions
Identify Fractions, Mixed Numbers & Improper Fractions
Quiz
•
3rd - 4th Grade
Discover more resources for Computers
10 questions
Fact Check Ice Breaker: Two truths and a lie
Quiz
•
5th - 12th Grade
10 questions
Video Games
Quiz
•
6th - 12th Grade
10 questions
Test Your Knowledge with 15 Fun Trivia Questions
Interactive video
•
6th - 10th Grade
15 questions
Memorial Day Trivia
Quiz
•
KG - 12th Grade
12 questions
Name that Candy
Quiz
•
KG - 12th Grade
20 questions
Guess The App
Quiz
•
KG - Professional Dev...
30 questions
K/H Final Review Part 1
Quiz
•
9th - 12th Grade
40 questions
NCFE Earth and Environmental Science Released Test
Quiz
•
9th - 12th Grade